-
Type: Improvement
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: None
The following pattern is problematic:
x = (attributes[:foo] ||= value)
This is because x receives value, not whatever ends up in attributes[:foo] after the value is converted to indifferent access. This was reported previously and again in https://jira.mongodb.org/browse/MONGOID-4874.
carbon% git g '(.*||=.*)' lib/mongoid/association/referenced/belongs_to.rb: (@inverse_type ||= "#{name}_type") if polymorphic? lib/mongoid/atomic.rb: (delayed_atomic_pulls[document.association_name.to_s] ||= []).push(document) lib/mongoid/atomic.rb: (delayed_atomic_unsets[document.association_name.to_s] ||= []).push(document) lib/mongoid/criteria/modifiable.rb: (@create_attrs ||= {}).merge!(attrs) lib/mongoid/extensions/hash.rb: (consolidated[key] ||= {}).merge!(value) lib/mongoid/extensions/hash.rb: (consolidated["$set"] ||= {}).merge!(key => mongoize_for(key, klass, key, value)) lib/mongoid/fields.rb: (attributes[name] ||= {}).with_indifferent_access lib/mongoid/persistable/pushable.rb: existing = send(field) || (attributes[field] ||= []) lib/mongoid/persistable/pushable.rb: existing = send(field) || (attributes[field] ||= []) lib/mongoid/query_cache.rb: (@cached_documents ||= []).concat(documents)
- related to
-
MONGOID-4874 Values seem to be lost when using add_to_set on a non-existent attribute on a loaded instance
- Closed
- links to