module MR::JsonField::Record::InstanceMethods

Private Instance Methods

json_field_sync_all_json_fields_on_save() click to toggle source

this makes it so changes that are done to the JSON object are persisted to the DB without having to re-write the entire field, for example if the json field is a hash then a change to an individual key's value needs to get re-encoded and stored in the source field, since the json field writer wasn't used it won't get encoded, this callback fixes the issue by ensuring all json fields get synced before we save the record

# File lib/mr/json_field/record.rb, line 28
def json_field_sync_all_json_fields_on_save
  self.model.class.json_field_accessors.each do |field_name|
    self.model.send("#{field_name}=", self.model.send(field_name))
  end
end