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

Misbehaviour in "uniqueness" validation #2

Open
loureirorg opened this issue Aug 12, 2013 · 4 comments
Open

Misbehaviour in "uniqueness" validation #2

loureirorg opened this issue Aug 12, 2013 · 4 comments

Comments

@loureirorg
Copy link

ActiveRecord's built-in uniqueness validation does not account for records deleted by paranoid2.

@loureirorg
Copy link
Author

a workaround is to use:

uniqueness: { conditions: -> { where(deleted_at: nil) } }

instead of:

uniqueness: true

@yury
Copy link
Member

yury commented Aug 12, 2013

Uniqueness validator by default uses unscoped scope

Not sure if we need to change this. You won't be able to restore deleted record (it would be invalid)

@loureirorg
Copy link
Author

actasparanoid has solved this by adding a custom uniqueness validator.

its use:

validates_uniqueness_of_without_deleted :name

istead of:

validates_uniqueness_of :name

@yury
Copy link
Member

yury commented Aug 12, 2013

@loureirorg you can use following scope to make code a little bit cleaner for now.

uniqueness: { conditions: -> { paranoid_scope } }

I will think more about this validator.

Thank you for your report

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