ruby on rails - MongoDB help (relationships) -
i have class foo embedded object bar. every time foo created, want bar created. bar initiated passing variables foo. how can accomplish this?
thanks
use before_create hook auto create bar. like
class foo include mongo.... attr_reader :new_bar before_create :create_bar def create_bar self.bars << new_bar end end
that way can still validate bar (using new_bar or whatever want).
both mongomapper , mongoid have before_create hook, should fine in either.
Comments
Post a Comment