-
Notifications
You must be signed in to change notification settings - Fork 901
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
Deal with on: []
#500
Deal with on: []
#500
Conversation
I think this looks great! I also think the work done here will make it easier to knock out #463, which is something I've been struggling with, and one of the few issues I want to make sure is addressed before the |
close #481; Provide support for manual versioning
@@ -269,6 +270,7 @@ def touch_with_version(name = nil) | |||
|
|||
attributes.each { |column| write_attribute(column, current_time) } | |||
save! | |||
record_update(true) if self.class.paper_trail_options[:on] == [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my code I need to do touch_with_version because something in my metadata on the version has changed, not the object itself, but this line stops me from actually doing a record_update since my model has option[:on] set to nil, which will default it to [:create, :update, :destroy]. So is tocuh_with_version only meant to be used on models without automatic versions on update/create/destroy?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"something in my metadata on the version has changed", then shouldn't you just be updating the version record directly instead of generating a new version? I'm not sure I'm following you. touch_with_version
can be called regardless of what your on
option is.
This line is here to ensure that in cases where PaperTrail
is essentially set to not do recordings on changes, users can still manually generate versions via touch_with_version
. The following line in this method (save!(:validate => false)
) should generate versions if you have options[:on]
set to nil
, or if :update
is in the collection. Hope this helps.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated to your discussion, I think I found a bug. It sounds like touch_with_version
should always create a version, but I think I found (and fixed) a situation where it doesn't: #563
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@batter Yes, I see that save!(:validate => false)
should be enough, but because my record doesn't change, it seems like active record wonth fire after_update, and hence the version will no be created.
Foo.last.touch_with_version
Foo Load (0.4ms) SELECT "foos".* FROM "foos" ORDER BY "foos"."id" DESC LIMIT 1
(0.1ms) begin transaction
(0.1ms) commit transaction
=> true
But this seems like it will work with the PR from @jaredbeck . Thank you
See #481 for more discussion. This pull request enables
on: []
to disable all automatic versioning, yet still forcestouch_with_version
to write a version.