Currently, referencing a field which is omitted from #only produces ActiveModel::MissingAttributeError. However, this field can be written to:
However, this write is not persisted:
... and reading person.age after writing it still yields ActiveModel::MissingAttributeError.
This ticket is to investigate whether it is possible to write to attributes omitted in #only list, and when doing so change the list of loaded attributes to include attributes written to.
Note that Mongoid provides 4 ways to write data into fields:
Generated field accessor (model.field = 'foo')
write_attribute (model.write_attribute(:field, 'foo'))
= (model['field'] = 'foo'), this is an alias of write_attribute
set (model.set(field: 'foo')), per
Because the set method involves a model instance attribute write (write_attribute), a solution for this ticket would likely enable writes via all four possible mechanisms.