I have a problem with the usage of validates_uniqueness_of that I hope someone can help throw a light on. With a new record, this validation works fine. But my problem came when I am updating a record. I was not able do it because it tells me that field value already exists. I was actually updating the value of other fields. According to the documentation which says "When the record is updated, the same check is made but disregarding the record itself." And it seems like this isn''t happening. Just wondering what is it that I am not doing correctly. I am using Rails 2.1.0 Thanks in advance for your inputs, Steve --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Found the reason why it wasn''t working in the Update mode. There was another record with the same field value as the one that I was updating. I missed that test record previously created. Once I remove all duplicated records, the validate_uniqueness_of works as expected in the Update. Steve On Sep 2, 10:50 am, stevel <isig...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I have a problem with the usage of validates_uniqueness_of that I > hope someone can help throw a light on. With a new record, this > validation works fine. But my problem came when I am updating a > record. I was not able do it because it tells me that field value > already exists. I was actually updating the value of other fields. > > According to the documentation which says "When the record is updated, > the same check is made but disregarding the record itself." And it > seems like this isn''t happening. Just wondering what is it that I am > not doing correctly. I am using Rails 2.1.0 > > Thanks in advance for your inputs, > > Steve--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Sep 3, 7:52 pm, stevel <isig...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Found the reason why it wasn''t working in the Update mode. There was > another record with the same field value as the one that I was > updating. I missed that test record previously created. Once I remove > all duplicated records, the validate_uniqueness_of works as expected > in the Update.Consider putting a unique index on your unique columns in the database. Christian --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---