我有一个模型
class Post
include Mongoid::Document
include Mongoid::Timestamps
embeds_one :comment
end
我有评论课
class Comment
include Mongoid::Document
include Mongoid::Timestamps
embedded_in :post
field :title
field :description
end
我还有另一个从评论继承的类
class RecentComment < Comment
# certain methods
end
现在我希望能够创建RecentComment
通过,post
如果我这样做Post.last.build_comment(:_type => "RecentComment")
新的评论将不会是_type:"RecentComment"
,同样如果我这样做Post.last.build_recent_comment
,它会给我错误的说 sth like undefined method build_recent_comment for Post class
。如果post
有的话,references_many :comments
我应该Post.last.build_comments({}, RecentComment)
没有任何问题。但我不知道RecentComment
在这种情况下如何用类构建一个对象。如果有人可以帮助那将是 gr8!
注意:我正在使用gem 'mongoid', '~> 2.0.1'