I have a model
class Post
include Mongoid::Document
include Mongoid::Timestamps
embeds_one :comment
end
and I have comment class
class Comment
include Mongoid::Document
include Mongoid::Timestamps
embedded_in :post
field :title
field :description
end
And I have another class inherited from comment
class RecentComment < Comment
# certain methods
end
Now I want to be able to create RecentComment
through post
if I do Post.last.build_comment(:_type => "RecentComment")
the new comment will not be of _type:"RecentComment"
, and similarly if I do Post.last.build_recent_comment
, it gives me error saying sth like undefined method build_recent_comment for Post class
. If the post
had references_many :comments
I should have done Post.last.build_comments({}, RecentComment)
without any problems. But I don't know about how to build an object with RecentComment
class in this case. If anybody could help that'd be gr8!
Note: I am using gem 'mongoid', '~> 2.0.1'