Add options for uniqueness validations. Resolves #319#333
Conversation
|
This will break behaviour for people already using the Wasn't sure if we should handle that case as the |
|
@BenMorganIO @jhawthorn Could we hope that it sometimes will be merged? |
|
Don't custom paranoid gem.You can write: |
| class Client < ActiveRecord::Base | ||
| acts_as_paranoid | ||
|
|
||
| validates :name, uniqueness: { paranoia: :with_deleted } |
There was a problem hiding this comment.
Don't custom paranoid gem.You can write:
validates :name, uniqueness: {conditions: ->{with_deleted}}
| class Client < ActiveRecord::Base | ||
| acts_as_paranoid without_default_scope: true | ||
|
|
||
| validates :name, uniqueness: { paranoia: :without_deleted } |
There was a problem hiding this comment.
Don't custom paranoid gem.You can write:
validates :name, uniqueness: {conditions: ->{with_deleted}}
There was a problem hiding this comment.
Don't custom paranoid gem.You can write:
validates :name, uniqueness: {conditions: ->{with_deleted}}
Doesn't work for me
There was a problem hiding this comment.
Doesn't work for me either in rails v4.2.10 using MySQL. Traced it a bit and I found that rails wasn't actually removing the scope via the unscope method because of the way the relation query is set up. By the time it hits here, the relation is wrapped and chained with an AND query. It doesn't get through this case statement to actually remove the column from the scope because the relation rel is a Arel::Nodes::And at that point.
I just ended up making my own validator which manually checked for uniqueness against the unscoped records to move forward.
Paranoia doesn't support unique validation including deleted records: rubysherpas/paranoia#333 We use a custom validator, ScopedUniquenessValidator to avoid the issue
Paranoia doesn't support unique validation including deleted records: rubysherpas/paranoia#333 We use a custom validator, ScopedUniquenessValidator to avoid the issue
Paranoia doesn't support unique validation including deleted records: rubysherpas/paranoia#333 We use a custom validator, ScopedUniquenessValidator to avoid the issue
Paranoia doesn't support unique validation including deleted records: rubysherpas/paranoia#333 We use a custom validator, ScopedUniquenessValidator to avoid the issue
For with_default_scope add a
paranoia: :with_deletedoption when you want to ensure uniqueness on all records.For without_default_scope add a
paranoia: :without_deletedoption when you want to ensure uniqueness on only non-deleted records.