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

after_(save|update) callbacks should see dirty state from before save

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

      ActiveRecord clears its dirty state after the callbacks are fired so that it is available in the callbacks. Mongoid is clearing the dirty state between the before and after callbacks are fired.

      class Person
      include Mongoid::Document
      field :name, :type => String
      before_update :print_changes
      after_update :print_changes
      def print_changes
      puts changes.inspect
      end
      end

      Person.new(:name => "Durran").tap(&:save!).update_attributes(:name => "Jordan")
      #=>

      {"name"=>["Durran", "Jordan"]}

      #=> {}

      Workaround: access #changes, #name_changed?. normally in before callbacks and #previous_changes in after callbacks

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

              Created:
              Updated:
              Resolved: