【发布时间】:2010-04-08 21:31:20
【问题描述】:
我的代码有问题
class Post < ActiveRecord::Base
end
class NewsArticle < Post
has_many :comments, :as => :commentable, :dependent => :destroy, :order => 'created_at'
end
class Comment < ActiveRecord::Base
belongs_to :commentable, :polymorphic => true, :counter_cache => true
end
并且在尝试去获取一些新闻文章的 cmets 我在日志中看到的类似
Comment Load (0.9ms) SELECT "comments".* FROM "comments" WHERE ("comments"."commentable_id" = 1 and "comments"."commentable_type" = 'Post') ORDER BY created_at
奇怪的是 "commentable_type" = 'Post'。 怎么了?
PS:Rails 2.3.5 && ruby 1.8.7(2010-01-10 补丁级别 249)[i686-darwin10]
【问题讨论】:
标签: ruby-on-rails activerecord polymorphic-associations single-table-inheritance