Permalink
Browse files

added back link to _owner for embedded docs

  • Loading branch information...
1 parent 6e87c79 commit bada68728491347944908f18ec4210ae650e59dc @magnetised magnetised committed with jnunemaker Jan 11, 2010
@@ -19,7 +19,7 @@ def self.included(model)
plugin Plugins::Serialization
plugin Plugins::Validations
- attr_accessor :_root_document
+ attr_accessor :_root_document, :_owner
end
super
@@ -41,6 +41,7 @@ def _root_document
def assign_root_document(*docs)
docs.each do |doc|
doc._root_document = _root_document
+ doc._owner = owner
end
end
end
@@ -133,6 +133,17 @@ def setup
doc.people.first._root_document.should == doc
doc.people.first.pets.first._root_document.should == doc
end
+ should "create a reference to the owning document for all embedded documents before save" do
+ doc = @klass.new
+ meg = @person_class.new(:name => 'Meg')
+ pet = @pet_class.new(:name => 'Sparky', :species => 'Dog')
+
+ doc.people << meg
+ meg.pets << pet
+
+ doc.people.first._owner.should == doc
+ doc.people.first.pets.first._owner.should == doc.people.first
+ end
should "create a reference to the root document for all embedded documents" do
sparky = @pet_class.new(:name => 'Sparky', :species => 'Dog')
@@ -145,6 +156,19 @@ def setup
doc.people.first._root_document.should == doc
doc.people.first.pets.first._root_document.should == doc
end
+ should "create a reference to the owning document for all embedded documents" do
+ doc = @klass.new
+ meg = @person_class.new(:name => 'Meg')
+ pet = @pet_class.new(:name => 'Sparky', :species => 'Dog')
+
+ doc.people << meg
+ meg.pets << pet
+ doc.save
+
+ doc.reload
+ doc.people.first._owner.should == doc
+ doc.people.first.pets.first._owner.should == doc.people.first
+ end
end
should "allow finding by id" do

0 comments on commit bada687

Please sign in to comment.