Readonly in field of type Hash in MongoId not work property
class Model
include Mongoid::Document
field :data, type: Hash
attr_readonly :data
end
This code is ok:
Model.create!(data: { foo: 'bar' })
puts Model.last.data # => { foo: 'bar' }
Model.update!(data: { baz: 'bar' }) # => raise exception
But when edit the hash directly the readonly not work:
model_instance = Model.last
model_instance.data # => { foo: 'bar' }
model_instance.data[:baz] = 'bar'
model_instance.update!
model_instance.reload
model_instance.data # => { foo: 'bar', baz: 'bar' } # problem, the values are saves in db.
who i could put readonly in hash fields?