Just to be crystal clear, what a number of these replies are attempting 
to tell you is that you cannot rely on validates_uniqueness_of.

Excerpt from the Rails docs on validation:
-----------------------------
Concurrency and integrity

Using this validation method in conjunction with ActiveRecord::Base#save 
does not guarantee the absence of duplicate record insertions, because 
uniqueness checks on the application level are inherently prone to race 
conditions. For example, suppose that two users try to post a Comment at 
the same time, and a Comment’s title must be unique. At the 
database-level, the actions performed by these users could be 
interleaved in the following manner:
-----------------------------

If two separate requests are received at virtually the same instant then 
validate_uniqueness_of can fail silently. You will end up with 
duplicates in the database that your validation specifically tries to 
avoid.

This is why the unique index across the two columns is necessary. This 
can only be reliably prevented at the database level. If this index 
exists and the validates_uniqueness_of fails due to a race condition the 
database layer will raise and exception. So you need to be prepared for 
this, even when using validates_uniqueness_of, by rescuing from the 
possible exception.
-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to