-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: 7.1.0
-
Component/s: Attributes
-
None
It seems when an instance is loaded from a database, its `attributes`
method returns an instance of `BSON::Document`. This causes some
surprising behavior when we use `#add_to_set` on that loaded instance.
When a value is assigned to a `BSON::Document` instance, it gets
modified:
https://github.com/mongodb/bson-ruby/blob/master/lib/bson/document.rb#L87-L89
During modification, the attribute loses its reference to the original
value, however the `add_to_set` method relies on this reference:
Since that reference is broken, it no longer update the instance's
attribute and the value is lost in memory, though still retained in the
DB.
I made a PR here that I hope can help:
- is related to
-
MONGOID-4875 Eliminate x = (attributes[:foo] ||= value) pattern
- Closed
- links to