ruby on rails - Mongoid references_many ids array population -
i have question regarding mongoid id storage references_many.
suppose have following classes:
class include mongoid::document field :name attr_accessible :name, :b_ids references_many :bs, :stored_as :array, :inverse_of :a end class b include mongoid::document field :name attr_accessible :name, :a_id referenced_in :a end
if following:
a = a.create(:name => "a1") b = b.create(:name => "b1") b.a =
should expect a.b_ids array array contains b's id?
the behaviour seeing b.a_id contains a's id, a.b_ids not contain b's id.
is id array on a's side supposed manually updated?
btw, if a.bs << b, a.b_ids gets updated correctly.
to answer own question, id arrays not automatically set @ moment. feature planned included once refactor branch of mongoid released.
this info comes thread: http://groups.google.com/group/mongoid/browse_thread/thread/9ac74dc9a08a5fe2/d3a7c2404b67abfa
until then, ids have tracked manually.
an example be:
class include mongoid::document field :name attr_accessible :name, :b_ids references_many :bs, :stored_as :array, :inverse_of :a def add_b b bs << b self.save end def remove_b b b_ids.delete b.id b.save end end class b include mongoid::document field :name attr_accessible :name, :a_id referenced_in :a end = a.create(:name => "a1") b = b.create(:name => "b1") b.a = a.add_b b
Comments
Post a Comment