Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

.touch doesn't create a version #329

Closed
bokmann opened this Issue · 3 comments

2 participants

@bokmann

I have a particular issue I'm solving by making related elements in a object graph call '.touch' on a root node of the graph, forcing the updated_at field to change (which gives me the bounds on a date query I'm doing).

It would be really useful if .touch created a new version. As a workaround I have created a method called '.tickle' that increments an integer that I otherwise ignore, but that is slightly hackish.

Potentially related to #323

@batter
Collaborator

So touch doesn't create a version because it doesn't trigger ActiveRecord::Callbacks like a normal update does, and PaperTrail generates versions for updates from a before_update callback.

I sort of think that before_update should kick off update callbacks in ActiveRecord, but it's not technically an update in the conventional sense of the word, so I can understand why it might not, but that is why versions aren't getting generated...

We may be able to override the touch method for these models so it invokes update_attributes instead of the touch method, but I'm not sure it's a good idea. It might make more sense to make a different but similar method like touch_with_version?

@batter
Collaborator

Did some more research into this. Apparently there is an after_touch callback, which we may be able to leverage for this issue.. I'll keep digging and see if I can come up with a solution that makes sense.

@batter batter self-assigned this
@batter batter added this to the 3.0.1 milestone
@batter batter closed this in 2a7225f
@batter
Collaborator

@bokmann - I decided to add a touch_with_version instance method to the methods that get mixed into a model's instance methods when you declare has_paper_trail on a model for the time being.

I've been thinking it may make sense to change the callback that gets fired when you update a model's attributes to use an after_update callback instead of an before_update callback like it does currently, and at that point I will probably hook into that after_touch callback. Or it may make sense to use an alias_method_chain so there is still a touch_without_version option, I haven't decided yet. But these changes probably won't happen until version 3.1.0. Thanks for the suggestion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.