-
Type: Bug
-
Resolution: Fixed
-
Priority: Unknown
-
Affects Version/s: None
-
Component/s: None
-
Minor Change
When a field of type Array is declared, and a value is assigned to it, and the value is an array of hashes, the inner hashes of the value are retained as is in the model's attributes. If the hashes are genuine Hash instances (not BSON::Document or AS::HashWithIndifferentAccess), these hash instances are not indifferently accessible.
Upon persistence and load from database, the same data becomes an array of BSON::Document instances which are indifferently accessible.
I think Mongoid should make the hashes indifferently accessible by converting them into BSON::Document instances upon assignment, so that access of components of attributes works the same before and after persistence.
class Bar include Mongoid::Document field :a, type: Array field :h, type: Hash end bar = Bar.new(a: [{foo: 42}]) # 42 p bar.a.first[:foo] # nil p bar.a.first['foo'] bar.save! bar.reload # 42 p bar.a.first[:foo] # 42 p bar.a.first['foo']
- related to
-
MONGOID-5270 Implement .tally method for Mongoid#Criteria
- Closed