0
我有几个可评论的模型(文章,文章等)。目前各commentable模型包含以下关联Rails多态模型 - 基类
has_many :comments, :as => :commentable
和注释模型包含:
belongs_to :commentable, :polymorphic => true
我commentable模型有一些相似的特点,我想他们是能够使用一些相同的功能。但是,我认为MTI(多表继承)对于这种情况可能是过度的。我可以创建一个他们都继承的基础模型类吗?即:
class Comment < ActiveRecord::Base
belongs_to :commentable, :polymorphic => true
end
class Commentable < ActiveRecord::Base
has_many :comments, :as => :commentable
validates_presence_of :body
def some_function
...
end
end
class Article < Commentable
...
end
class Post < Commentable
...
end
伟大的信息,感谢您的! – 2012-02-26 00:11:36