Question

1.9.3p448 :014 > l.reload
 => #<Lesson _id: 527246641d41c81d14000006, title: "ola"> 
1.9.3p448 :015 > l.changed?
 => false 
1.9.3p448 :016 > l.changes
 => {} 
1.9.3p448 :017 > l.previous_changes
 => {"title"=>["olaaaaa", "ola"]} 
1.9.3p448 :018 > l.changed?
 => false 
1.9.3p448 :019 > l.update_attributes(title: "olaaa")
 => true 
1.9.3p448 :020 > l.changes
 => {} 
1.9.3p448 :021 > l.changed?
 => false 

I have updated the attribute "title" but when I try l.changed? I get false.

I know the new_record? method, to know if a object is a new object but I need to know if a object is updated.

I would like to know, how can I know if a object has been updated with mongoid 3.x?

Was it helpful?

Solution

When you reload, save, update, the changes are moved to previous_changes. You also have access to the changes on callbacks, otherwise you will have to use previous_changes . Thats by design, to be consistent with ActiveRecord.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top