-
Type: Bug
-
Resolution: Fixed
-
Priority: Minor - P4
-
Affects Version/s: 7.0.8, 6.4.7
-
Component/s: Attributes
-
None
-
Fully Compatible
The read_attribute (version 6) / read_raw_attribute (version 7) fails to return a field from an embedded model if the parent was loaded with only (and the embedded model is listed in only).
Example:
class Model include Mongoid::Document embeds_one :inner_model end class InnerModel include Mongoid::Document embedded_in :model field :name, type: String end model = Model.create model.create_inner_model(name: 'test') model = Model.only(:inner_model).first puts model['inner_model.name'] # <= this fails with ActiveModel::MissingAttributeError
It works with only('inner_model.name'), which is also tested in attributes_spec, but it's not really what I want to do - if I include a whole embedded model, I expect I can read any of its fields.
I'm willing to make a patch for both version 6 and 7, if you confirm that this is not intentional behavior.
- is related to
-
MONGOID-5059 `set` nilifies attributes excluded via `only`
- Closed
- related to
-
MONGOID-4952 Unable to access embedded fields in projected query results
- Closed
- links to