I am trying to use the act_as_paranoid plugin to gently delete records. I used to control it using the flag in db. I know that this plugin will omit the entry from the search and will find if the entry is softly deleted. I want to know if I have validation in the type model validates_uniqueness_of :emailand I deleted (gently deleted) the email entry " prince@gmail.com ". Now, when I try to create a new user with the same email address, verification will be performed and prevent the creation of a new entry. Or will he omit the soft remote record, as for finds? (I would like this to happen, of course.)
validates_uniqueness_of :email
acts_as_paranoiddoes not override validates_uniqueness_of, therefore, if you (gently) deleted the entry by email " prince@gmail.com ", you cannot create a new entry with the same email address.
acts_as_paranoid
validates_uniqueness_of
An easy fix for this is to add scope for validates_uniqueness_of:
validates_uniqueness_of :email, :scope => :deleted_at
This way, you can have any number of (soft) deleted entries with the email address " prince@gmail.com " and still create a new entry with the same email address.
From our testing, a fix that acts_as_paranoidaffects deletion, so you get two entries. Of most conversations on the Internet, this is probably what you expect.
. , "" , , . , , . acts_as_paranoid, - .
, (:with_deleted => true), . , . , , " " .
:with_deleted => true
yor "rails3_acts_as_paranoid", ,
ActiveRecord's built-in uniqueness check does not take into account records deleted by ActsAsParanoid. If you want to check the uniqueness of not only deleted records, use the validates_as_paranoid macro in your model. Then, instead of using validates_uniqueness_of, use validates_uniqueness_of_without_deleted. This will result in deleted records being counted from the uniqueness check.
You must specify the following method,
acts_as_paranoid validates_as_paranoid validates_uniqueness_of_without_deleted :name
Source: https://habr.com/ru/post/1791221/More articles:Does Apple allow me to request promotional codes for apps rated 17+? - itunesconnectHow should I be mocking this simple service level method? - .netHow to prevent assembly if another assembly fails? - continuous-integrationAre files uploaded with the hg clone deleted? - mercurialflex 4: mxFlex 4: mxflex4 mxGridLayout help in Java - javaC ++ boost :: shared_ptr and boost :: weak_ptr & dynamic_cast - boostPrimitive casting or byte trimming - javaAll Articles