-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
-
Labels:None
Two issues here, but I think they might be related. Take collection-level document A with embedded document B. Document B embeds_one document C.
1. Update any field on B, call save on B.
2. Check the fields on B; they're changed.
3. Reload A. Now get B again. Where are your changes? They're gone.
Also, you can trigger a "conflicting mods in update" error easily with this setup.
1. Create & save A without any sub-documents.
2. Instantiate new B and new C, assign C to B and B to A.
3. Call save on A. Your mods are now in conflict.
I've written test cases into persistence_spec.rb (right after line 255) to demonstrate these scenarios. I'll post them below. I'm looking for a solution, but there's a lot of code to absorb. If there's something I'm doing wrong or if anyone has a clue where these issues might lie, I would surely appreciate it.
it "should allow saves sub-documents with embeds_one" do
person = Person.create(:title => 'The Boss', :ssn => '1234567890')
phone = Phone.new(:number => '123-456-7890')
cc = CountryCode.new(:code => 12)
phone.country_code = cc
person.phone_numbers << phone
person.save
person.phone_numbers[0].country_code.should == 12
person.delete
end
it "should save attributes for sub-documents with embeds_one" do
person = Person.new(:title => 'The Boss', :ssn => '0987654321')
phone = Phone.new(:number => '123-456-7890')
cc = CountryCode.new(:code => 12)
phone.country_code = cc
person.phone_numbers << phone
person.save
person.phone_numbers[0].country_code[:code].should == 12
person.phone_numbers[0][:number].should == '123-456-7890'
phone = person.phone_numbers[0]
phone.update_attributes(:number => '098-765-4321')
phone.save
person.phone_numbers[0][:number].should == '098-765-4321'
person.reload
person.phone_numbers[0][:number].should == '098-765-4321'
person.delete
end