DavidPaquet
2008-Jun-21 19:27 UTC
Newbie : Easiest way to validate uniqueness of 2 fields that are related
Hello everyone Just to be sure, what is the easiest way to validate that a combination of 2 fields is unique in my model ? Example : I have Posts and Comments A posts can have multiple comments (so post_id is not unique) and multiple comments can have the same title (title is not unique either). But, I don''t want 2 comments from the same post to have the same title. How is the easiest way to test that in my Comment model ? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Jun-21 22:45 UTC
Re: Newbie : Easiest way to validate uniqueness of 2 fields that are related
On Jun 21, 8:27 pm, DavidPaquet <david.paq...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello everyone > > Just to be sure, what is the easiest way to validate that a > combination of 2 fields is unique in my model ? >That''s what the :scope option on validates_uniqueness is for. Fred --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---