Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Uniqueness validation uses a proc to specify the
:conditions
option.
This is a follow up to #5321 and follows the general direction in AR to make things lazy evaluated.
- Loading branch information
Showing
3 changed files
with
23 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This is great stuff, but by using this you can't deal with Concurrency and integrity Problem easily anymore.
The doc below says
"Using this validation method in conjunction with ActiveRecord::Validations#save does not guarantee the absence of duplicate record insertions, because uniqueness checks on the application level are inherently prone to race conditions"
It suggests a workaround by simply adding a unique index.
In case of such :conditions option, this is not that simple any more. You could solve this by adding stored_procedure for checking integrity or using a partial unique index in postgres. The point is, that you have to write this logic twice - in application and in the backend, making the validator kind of useless, since it's not actually garanteeing uniqueness. The same also applies for the :allow_nil option. It's always true for the unique indices in mysql for example and if you do not set it, you would actually need a stored porcedure again for the right integrity check.
Is there any way, we can generate this stored procedures for the unique validators? It must not happen automaticly.
Just a simple generate method