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

#reload doesn't run callbacks

    • Type: Icon: Task Task
    • Resolution: Done
    • 2.1.3
    • Affects Version/s: None
    • Component/s: None
    • None

      Because Mongoid updates the attributes directly from the DB:
      https://github.com/mongoid/mongoid/blob/master/lib/mongoid/document.rb#L149
      Rather than via the model class like ActiveRecord does:
      https://github.com/rails/rails/blob/master/activerecord/lib/active_record/persistence.rb#L240

      I've got model logic that uses callbacks to cast values in a Hash between Time (for MongoDB) and Date (for my app), but to get it to run I need to do:

      obj.reload
      obj.run_callbacks :initialize

      This is a bigger pain when other things call reload under the hood (e.g. machinist_mongo) expecting it to run callbacks, then give me back an object that behaves unexpectedly.

            Assignee:
            Unassigned Unassigned
            Reporter:
            chrisberkhout chrisberkhout
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: