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

Deal with on: [] #500

Merged
merged 3 commits into from
Mar 19, 2015
Merged

Conversation

marnen
Copy link
Contributor

@marnen marnen commented Mar 18, 2015

See #481 for more discussion. This pull request enables on: [] to disable all automatic versioning, yet still forces touch_with_version to write a version.

@marnen marnen mentioned this pull request Mar 18, 2015
@batter batter added this to the 4.0.0 milestone Mar 19, 2015
@batter
Copy link
Collaborator

batter commented Mar 19, 2015

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 4.0.0 release. Cheers!

batter added a commit that referenced this pull request Mar 19, 2015
close #481; Provide support for manual versioning
@batter batter merged commit f78ed9f into paper-trail-gem:master Mar 19, 2015
batter added a commit that referenced this pull request Mar 19, 2015
@marnen marnen deleted the handle-on-nothing-correctly branch March 19, 2015 23:36
@@ -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] == []

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?

Copy link
Collaborator

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.

Copy link
Member

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

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

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

Successfully merging this pull request may close these issues.

4 participants