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

First save ignores :if condition #11

Open
Simbul opened this issue Oct 13, 2011 · 3 comments
Open

First save ignores :if condition #11

Simbul opened this issue Oct 13, 2011 · 3 comments

Comments

@Simbul
Copy link

Simbul commented Oct 13, 2011

When saving a versioned model for the first time, a version is created regardless of the :if condition.

E.g. if I do

acts_as_versioned :if => Proc.new {|item| false}

I will still get a new record in the _versions table when calling the first save() (or create()) on my model.

I suppose there's a reason for this, but from my point of view when the :if condition is false no version should be saved, ever.

I think the behavior stems from line 391 in acts_as_versioned.rb.

@saving_version = new_record? || save_version?

Why do new records get to bypass the version saving conditions?

@technoweenie
Copy link
Owner

I dont remember... I guess so there's always an initial versioned record? I can't believe anyone still uses this :)

@Simbul
Copy link
Author

Simbul commented Oct 13, 2011

According to my tests it is possible to honour the :if condition and still get correct results. I'll submit a pull request momentarily.

While we're at it, do you know of any other gem that does the same job as yours and is actively supported? :)

@technoweenie
Copy link
Owner

Nope. I'm sure there's something out there.

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