ruby on rails - single table inheritance with embeds_one mogoid -
i have model
class post include mongoid::document include mongoid::timestamps embeds_one :comment end and have comment class
class comment include mongoid::document include mongoid::timestamps embedded_in :post field :title field :description end and have class inherited comment
class recentcomment < comment # methods end now want able create recentcomment through post if post.last.build_comment(:_type => "recentcomment") new comment not of _type:"recentcomment", , if post.last.build_recent_comment, gives me error saying sth undefined method build_recent_comment post class. if post had references_many :comments should have done post.last.build_comments({}, recentcomment) without problems. don't know how build object recentcomment class in case. if that'd gr8!
note: using gem 'mongoid', '~> 2.0.1'
maybe try
class post include mongoid::document include mongoid::timestamps embeds_one :recent_comment, :class_name => comment and make comment class polymorphic
class comment include mongoid::document include mongoid::timestamps field :type validates_inclusion_of :type, :in => ["recent", "other"]
Comments
Post a Comment