-
Type: Improvement
-
Resolution: Fixed
-
Priority: Minor - P4
-
Affects Version/s: None
-
Component/s: Docs
-
Fully Compatible
The reloading documentation (https://docs.mongodb.com/mongoid/master/reference/crud/#reloading) says:
> Use the reload method to fetch the most recent version of a document from the database:
However, in testing for MONGOID-5199 it appears that changed attributes are potentially remaining changed after reloading:
class Band include Mongoid::Document embeds_one :label end class Label include Mongoid::Document field :name, type: String embedded_in :band end b = Band.create! Band.with_session do |s| s.start_transaction label = Label.new(name: "Neil") b.label = label b.reload puts b.label # <Label _id: 61bcab66d1327a521a5054a9, name: "Neil"> s.commit_transaction end
The following example maintains a changed value but somehow it's not the most recent one:
Band.with_session do |s| s.start_transaction label = Label.new(name: "Neil") b = Band.new(label: label) b.save! b.label = nil b.label = label b.reload puts b.label # nil s.commit_transaction end
The scope of this ticket is to investigate whether changed attributes are retained through reload and update the documentation accordingly.
- is related to
-
MONGOID-5206 Reloading retains stale changed value
- Closed
-
MONGOID-5235 Add Feature Flag: Reloading retains stale changed value
- Closed
-
MONGOID-4484 Clarify that association assignment saves documents
- Closed
- related to
-
MONGOID-5199 Reloadable#reload_embedded_document doesn't respect session
- Closed
-
MONGOID-5238 Add Feature Flag: Reloadable#reload_embedded_document doesn't respect session
- Closed
- links to