-
Type: Bug
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: 5.0.2
-
Component/s: Associations, Persistence
-
None
-
Environment:Rails 4.2.3
-
Major Change
When using update_attributes, changes to embedded documents are not immediately reflected in the parent document's attributes hash. Reloading from MongoDB updates the attributes hash.
Example:
class Jam include Mongoid::Document embedded_in :womp end class Womp include Mongoid::Document embeds_many :jams accepts_nested_attributes_for :jams, allow_destroy: true end w = Womp.create! w.attributes #=> {"_id"=>BSON::ObjectId('58489d22a54d75c13c000006')} w.update_attributes({ jams_attributes: [ {} ] }) w.attributes #=> {"_id"=>BSON::ObjectId('58489d22a54d75c13c000006')} w.reload.attributes #=> {"_id"=>BSON::ObjectId('58489d22a54d75c13c000006'), "jams"=>[{"_id"=>BSON::ObjectId('58489d22a54d75c13c000007')}]} w.update_attributes({ jams_attributes: [ { id: w.jams.first.id, _destroy: true } ] }) w.attributes #=> {"_id"=>BSON::ObjectId('58489d22a54d75c13c000006'), "jams"=>[{"_id"=>BSON::ObjectId('58489d22a54d75c13c000007')}]} w.reload.attributes #=> {"_id"=>BSON::ObjectId('58489d63a54d75c13c000008'), "jams"=>[]}
- is related to
-
MONGOID-5312 Document attributes method in reference
- Closed