-
Type: Task
-
Resolution: Done
-
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")
#=>
#=> {}
Workaround: access #changes, #name_changed?. normally in before callbacks and #previous_changes in after callbacks