-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: 6.2.1
-
Component/s: Associations
-
Environment:MacOS, Ruby 2.3.5
-
Fully Compatible
I would expect that calling doc.reload would reload all embedded documents as well. This does not seem to be the case.
Given these documents:
class Foo include Mongoid::Document field :foo, type: String embeds_many :bar end class Bar include Mongoid::Document field :bar, type: String end
This piece of code highlights the issue:
Foo.create!(foo: 'foo1', bar: [Bar.new(bar: 'bar1')]) doc = Foo.first doc.bar = [Bar.new(bar: 'bar2')] doc.foo = 'foo2' p "-- After change" p doc.foo p doc.bar.first.bar doc.reload p "-- After reload" p doc.foo p doc.bar.first.bar doc.save! p "-- What's in the DB?" p Foo.first.foo p Foo.first.bar.first.bar
- is related to
-
MONGOID-5294 Expand documentation of which association operations immediately save documents
- Backlog
- related to
-
MONGOID-5205 Document reloading behavior for changed attributes
- Closed
- links to