Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-325

Support for [field]_will_change!

    • Type: Icon: Task Task
    • Resolution: Done
    • 12_01_17
    • Affects Version/s: None
    • Component/s: None
    • Labels:

      Leveraging the abilities of MongoDB and Mongoid, we have models that store a large, deeply nested hash of raw data. If we modify a deeply nested value in this hash, Mongoid will refuse to save it because modifying the nested hash modified the attribute in Mongoid in-place and doesn't trigger the dirty tracking in Mongoid, which means Mongoid will refuse to save the new value since it uses atomic updates.

      ActiveRecord/ActiveModel's dirty tracking suffers from the same issue since this is just how Ruby works, but they manage to avoid it to a large degree since ActiveRecord steers you toward "primative" datatypes. In the cases whey they can't avoid it, they provide a #attribute_will_change! method (and a dynamic #

      {field}

      _will_change! method) to manually trigger the dirty state. Not elegant, but better than nothing which is where I am now with Mongoid.

      http://api.rubyonrails.org/classes/ActiveModel/Dirty.html

            Assignee:
            Unassigned Unassigned
            Reporter:
            cgriego Chris Griego
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: