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? --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Maurício Linhares
2009-Feb-28 21:41 UTC
Re: validates_uniqueness_of - how did I get two users?
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) On Sat, Feb 28, 2009 at 5:49 PM, phil <phil-o0Q4Q1ys/oVBDgjK7y7TUQ@public.gmane.org> wrote:> > 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? > > >--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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 Linhareshttp://alinhavado.wordpress.com/(pt-br) |http://blog.codevader.com/(en) > > On Sat, Feb 28, 2009 at 5:49 PM, phil <p...-o0Q4Q1ys/oVBDgjK7y7TUQ@public.gmane.org> wrote: > > > 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?--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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. On Sat, Feb 28, 2009 at 4:39 PM, phil <phil-o0Q4Q1ys/oVBDgjK7y7TUQ@public.gmane.org> wrote:> > The odd thing is that the users were created through the website two > months apart!--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---