Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.touch doesn't create a version #329

Closed
bokmann opened this issue Feb 12, 2014 · 3 comments
Closed

.touch doesn't create a version #329

bokmann opened this issue Feb 12, 2014 · 3 comments
Assignees
Milestone

Comments

@bokmann
Copy link

bokmann commented Feb 12, 2014

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
Copy link
Collaborator

batter commented Feb 13, 2014

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
Copy link
Collaborator

batter commented Feb 18, 2014

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 Feb 18, 2014
@batter batter added this to the 3.0.1 milestone Feb 18, 2014
@batter batter closed this as completed in 2a7225f Feb 21, 2014
@batter
Copy link
Collaborator

batter commented Feb 21, 2014

@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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants