-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
-
None
class Parent include Mongoid::Document has_and_belongs_to_many :childs, :inverse_of => nil, :validate => false end class Child include Mongoid::Document field :hi, :type => String end
Mongoid 2.4.1, Rails 3.1.1
nader$ rails c Loading development environment (Rails 3.1.1) ruby-1.9.2-p290 :001 > p1 = Parent.create => #<Parent _id: 4f7348308035440918000001, _type: nil, child_ids: []> ruby-1.9.2-p290 :002 > p1.childs => [] ruby-1.9.2-p290 :003 > p1.child_ids = [Child.first.id, Child.last.id] => [BSON::ObjectId('4f7346d980354408da000001'), BSON::ObjectId('4f73472380354408da000004')] ruby-1.9.2-p290 :004 > p1.save => true ruby-1.9.2-p290 :005 > p1.childs => [] ruby-1.9.2-p290 :006 > p1.childs.count => 2 ruby-1.9.2-p290 :007 > p1.childs.length => 0