Forum: Ruby on Rails validates_uniqueness_of - how did I get two users?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
A07f0662e96a632d9447a710adadbe05?d=identicon&s=25 Phil Smy (phileuro)
on 2009-02-28 21:50
(Received via mailing list)
I have the following in my user model:

  validates_uniqueness_of   :login, :email, :case_sensitive => false

yet somehow I ended up with two users with the same email. Does this
line mean that the COMBINATION is unique (I didn't think it did).

Should I have this instead:

 validates_uniqueness_of   :login, :case_sensitive => false
 validates_uniqueness_of   :email, :case_sensitive => false

Any ideas?
A91bd6cef23eb3516245a092e196c4da?d=identicon&s=25 Maurício Linhares (mauricio)
on 2009-02-28 22:42
(Received via mailing list)
No, it doesn't mean that the combination is unique, it means that
:login and :email are going to be unique.

There are two possible reasons, the user was added manually at the
database (which is bad, as the database should have a unique index at
both columns) or you got into a racing condition, where the two
selects hit the database at the same time and thus both returned
false.

Best thing to do is to improve you database schema by creating some
unique indexes that reflect your validations.

-
Maurício Linhares
http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/
(en)
A07f0662e96a632d9447a710adadbe05?d=identicon&s=25 Phil Smy (phileuro)
on 2009-03-01 01:40
(Received via mailing list)
The odd thing is that the users were created through the website two
months apart!

On Feb 28, 10:41 pm, Maurício Linhares <mauricio.linha...@gmail.com>
92497f51734ed56687928d5fd68d870a?d=identicon&s=25 Sarah Mei (Guest)
on 2009-03-02 01:09
(Received via mailing list)
In ActiveRecord::Base, the save method takes a flag called
perform_validation, which you can set to false. Check your controller
code to make sure someone didn't decide to skip the validations
somewhere.
This topic is locked and can not be replied to.