-
Type: Bug
-
Resolution: Duplicate
-
Priority: Major - P3
-
None
-
Affects Version/s: 7.1.1
-
Component/s: Persistence
-
None
Example:
class A include Mongoid::Document include Mongoid::Timestamps::Short embeds_many :bs, cascade_callbacks: true accepts_nested_attributes_for :bs field :name end class B include Mongoid::Document include Mongoid::Timestamps::Short embeds_many :cs, cascade_callbacks: true accepts_nested_attributes_for :cs field :name end class C include Mongoid::Document include Mongoid::Timestamps::Short field :name end it 'push multiple' do a = A.create(name: "A Name") b = a.bs.create(name: "B Name") a.bs_attributes = { "0" => { "cs_attributes" => { "0" => { "name" => "C Name" } }, "id" => b.id.to_s }, "1" => { "name" => "New B Name" } } expect(a.atomic_updates).to eq({ "$push" => {"bs.0.cs"=>{"$each"=>[{"_id"=>b.cs.first.id, "name"=>"C Name"}]}}, :conflicts => {"$push"=>{"bs"=>{"$each"=>[{"_id"=>a.bs.last.id, "name"=>"New B Name"}]}}} }) a.send(:prepare_update, {}) do expect(a.atomic_updates).to eq({}) end
The first expectation looks good. bs.0.cs change in one push and other bs changes into other push.
After update callbacks, it looks different: updated_at fields move to first push, but bs.0.cs moves to conflicts too. This calls Updating the path 'bs' would create a conflict at 'bs' (40) (on mongo:27017, legacy retry, attempt 1) error.
- duplicates
-
MONGOID-4982 Cannot update a field on embedded association member, add another member and add a nested association to the first member in the same save call
- Closed
- is related to
-
MONGOID-4222 accept_nested_attributes doesn't work for multiple levels
- Closed
- links to