paranoid2
paranoid2 copied to clipboard
Misbehaviour in "uniqueness" validation
ActiveRecord's built-in uniqueness validation does not account for records deleted by paranoid2.
a workaround is to use:
uniqueness: { conditions: -> { where(deleted_at: nil) } }
instead of:
uniqueness: true
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)
actasparanoid has solved this by adding a custom uniqueness validator.
its use:
validates_uniqueness_of_without_deleted :name
istead of:
validates_uniqueness_of :name
@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