-
Notifications
You must be signed in to change notification settings - Fork 529
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
validates_uniqueness_of does not use "where deleted_at is null" #114
Comments
@codeodor Can you show me a situation with this failing? |
Sure, I added tests to each branch that show it failing.
The test creates a record, destroys it, and creates a new instance with the same name, and asserts whether the record is valid. At present, it is not. |
I encountered this problem too.
This code below will add book to user's favorite then remove it by soft-deleting. After that I cannot add book to favorite any more, because
|
+1. https://github.com/goncalossilva/acts_as_paranoid has validates_uniqueness_of_without_deleted. IMHO it should be default. @radar do you plan anything? |
@radar I added fixes to the rails3 and rails4 branches (of my fork, and thus the pull requests I made) where I had previously only included failing tests. I am not sure how you feel about it, but I don't really like the idea of Because of that, I used |
FWIW, I looked into the Rails4 branch failure on Travis CI. One is due to (I think) assert_nothing_raised being gone on the Rails 4.1 tests. I have no idea why the 4.0.2 test is failing -- It works for me locally on 1.9.3 and 2.0.0. I'm not sure if that's something I broke, or if it's been broken for a while. |
Any updates on this? :/ |
PR on the PR: codeodor#1 |
Thanks, merged it into mine. |
Is there any interest in getting that PR merged back here? If so, please submit it as a PR. |
Thanks for the fix @codeodor! I just hit this in my application and was able to pull the rails4 branch and it's fixed! 👍 |
Do I have to use 'validates_uniqueness_of' because using: validates :name, uniqueness: { scope: :user_id, message: :name_already_taken } Doesn't work |
@fwgroup-steven I'm not sure what Rails does under the hood, but I did change UniquenessValidator so I would assume they use the same thing in both places. You might check the version you're running though. These changes were accepted into the repository ?(June 20, 2015) after the latest released version on RubyGems (June 17, 2015): |
@codeodor Thanks for your response. I just realised I had an out of date version, now updated to 2.1.3. But it's still not working :( I have:
But I get: Name has already been taken Do you where I can start looking to figure out what is wrong? |
@fwgroup-steven Unfortunately that version was released before these changes were merged, so you would need to take a look at the commit and patch it in your app, or use |
I think the readme file needs to be updated. gem "paranoia", "~> 2.1.5" this solves the problem. |
@codeodor @radar We seem to be experiencing this issue in version 1.3.4 (which is the latest version of the gem for Rails 3). @codeodor mentioned pull requests for both rails 3 and rails 4 but the following does not work:
I've tried to use Updated:
so it looks like a new release, v1.3.5 needs to be released with the latest rails3 branch if possible thanks |
It's trivial in Rails 4 for the client code to fix by adding
:conditions
but that's not an option in Rails 3.Is there any interest in a fix for this, either by adding a new method (maybe append
_without_deleted
to the name, or fixing it to work to be consistent with the rest of the queries it modifies?The text was updated successfully, but these errors were encountered: