-
Notifications
You must be signed in to change notification settings - Fork 530
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
Add options for uniqueness validations. Resolves #319 #333
base: core
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -181,6 +181,30 @@ Client.restore(id, :recursive => true) | |
client.restore(:recursive => true) | ||
``` | ||
|
||
If you want to validate uniqueness but want to include deleted records: | ||
|
||
``` ruby | ||
class Client < ActiveRecord::Base | ||
acts_as_paranoid | ||
|
||
validates :name, uniqueness: { paranoia: :with_deleted } | ||
|
||
... | ||
end | ||
``` | ||
|
||
If you don't use the default_scope and want to validate uniqueness but want to exclude deleted records: | ||
|
||
``` ruby | ||
class Client < ActiveRecord::Base | ||
acts_as_paranoid without_default_scope: true | ||
|
||
validates :name, uniqueness: { paranoia: :without_deleted } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't custom paranoid gem.You can write: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Doesn't work for me There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't work for me either in I just ended up making my own validator which manually checked for uniqueness against the unscoped records to move forward. |
||
|
||
... | ||
end | ||
``` | ||
|
||
For more information, please look at the tests. | ||
|
||
#### About indexes: | ||
|
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.
Don't custom paranoid gem.You can write:
validates :name, uniqueness: {conditions: ->{with_deleted}}