This project is archived and is in readonly mode.
Added previous_changes to ActiveRecord::Dirty [PATCH]
-
Scott Barr
Reformatted the example, sorry about that
person = Person.find_by_name('bob') person.name = 'robert' person.changes # => {'name' => ['bob, 'robert']} person.save person.changes # => {} person.previous_changes # => {'name' => ['bob, 'robert']} person.reload person.previous_changes # => {} -
Scott Barr
- Tag changed from patch to activerecord, dirty, patch
-
orangechicken
Thank goodness for this! Having the dirty changes blown out after save severely limits the usefulness of the dirty state -- this seems like a good compromise.
-
CancelProfileIsBroken
- Tag changed from activerecord, dirty, patch to activerecord, bugmash, dirty, patch
-
Josh Sharpe
This patch doesn't apply cleaning for me. I like the idea though.
-
pjammer
This patch says the following when applied with git am :
/home/path/rails/.git/rebase-apply/patch:84: trailing whitespace. error: activerecord/lib/active_record/dirty.rb: does not exist in indexinspecting these lines it doesn't appear that there is whitespace however.
The concept is a good idea. Shouldn't you be more worried about what is saving in the before_save callback, vs. what was saved after? Just to play devil's advocate.
-
Scott Barr
I'll clean up the patch and resubmit.
-
Greg Sterndale
Verified.
Added a few extra tests.
-
Greg Sterndale
I've attached a patch.
-
David Trasbo
The patch does not apply cleanly to edge since activerecord/lib/active_record/dirty.rb has been moved.
-
Nick Quaranto
-
- This seems a bit overboard to me. Using
model.#{attribute}_washas always been enough for me, if you're changing it more than once that sounds like bad logic instead to me. I'd like to see some real use cases of this first.
- This seems a bit overboard to me. Using
-
-
Josh Nichols
+1, I could see this making the dirty a lot more useful.
A use case I would use this for goes something like:
- I have a Debate that has 'state' attribute for the current state (ie new, forfeited, etc) - I want to make notifications when this state changes - I could use an after_save callback to kick off a mailer to which includes both the old value and the new value. -
Greg Sterndale
Thanks David.
I've attached a patch for edge.
-
Greg Sterndale
Renamed the previous patch for clarity
-
Jeremy Kemper
- Assigned user set to Jeremy Kemper
- State changed from new to open
- Milestone changed from 2.x to 2.3.4
- Nice way to track an undo history in an after_save. Needs rebase against master.
-
Michael Koziarski
Adding Josh as he's looking at this in amo
-
David Trasbo
verified
-
Matt Jones
This may be useful, but at least part of your description is misleading - the changed? and was methods work fine inside after_save, as they aren't reset until after the transaction commits.
-
josh
- Assigned user changed from Jeremy Kemper to josh
- Milestone cleared.
-
josh
Lets put it in 3.0.
Can you please rebase against master. I'm about to make some changes to AR dirty tracking in the next few days. I'm extracting them out to AMo.
-
josh
- State changed from open to incomplete
-
Scott Barr
The original patch wouldn't apply because dirty.rb moved after I submitted the patch.
Let me know what this ticket needs and I'll put it together.
-
Josh Sharpe
- Tag changed from activerecord, bugmash, dirty, patch to activerecord, dirty, patch, previous_changes
- Title changed from Added previous_changes to ActiveRecord::Dirty to Added previous_changes to ActiveRecord::Dirty [PATCH]
Rebased Scott's patch for master.
-
josh
- State changed from incomplete to committed
