I need to modify the validates_uniqueness_of function so that it will check that the string is unique but only in its own category. For example right now I have validates_uniqueness_of :title so let''s say I have the :title "Title 1" already in the database with the :category of "1" then if i wanted to enter the :title "Title 1" in the database again BUT with a :category of "2" I need it to go through. In other words it should only create an error if I try to enter :title "Title 1" AND :category "1" Thanks in advance for any suggestions. -- Posted via http://www.ruby-forum.com/.
Rather than modifying that validation keyword, why not create your own? http://wiki.rubyonrails.com/rails/pages/HowToAddCustomValidationKeywords This may help with what you want to do, I''m not sure on what you''d have to put in the newly created keyword, but hopefully it''ll get you on the right track. On 4/27/06, BB <bbsaid@sfsu.edu> wrote:> > I need to modify the validates_uniqueness_of function so that it will > check that the string is unique but only in its own category. > > For example right now I have > > validates_uniqueness_of :title > > so let''s say I have the :title "Title 1" already in the database with > the :category of "1" > > then if i wanted to enter the :title "Title 1" in the database again BUT > with a :category of "2" I need it to go through. > > In other words it should only create an error if I try to enter :title > "Title 1" AND :category "1" > > Thanks in advance for any suggestions. > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Matt -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060427/9f758aa7/attachment.html
Matt Ramos wrote:> Rather than modifying that validation keyword, why not create your own? > > http://wiki.rubyonrails.com/rails/pages/HowToAddCustomValidationKeywords > > This may help with what you want to do, I''m not sure on what you''d have > to > put in the newly created keyword, but hopefully it''ll get you on the > right > track.Thanks Matt, I''ll take a look at that. I was just hoping there was a way to modify the existing validates function. -- Posted via http://www.ruby-forum.com/.
BB wrote:>I need to modify the validates_uniqueness_of function so that it will >check that the string is unique but only in its own category. > >For example right now I have > >validates_uniqueness_of :title > >so let''s say I have the :title "Title 1" already in the database with >the :category of "1" > >then if i wanted to enter the :title "Title 1" in the database again BUT >with a :category of "2" I need it to go through. > >In other words it should only create an error if I try to enter :title >"Title 1" AND :category "1" > >Thanks in advance for any suggestions. > > >validates_uniqueness_of :title, :scope => "category" Cheers Matthias Oesterle
matthibcn wrote:> BB wrote: > >>then if i wanted to enter the :title "Title 1" in the database again BUT >>with a :category of "2" I need it to go through. >> >>In other words it should only create an error if I try to enter :title >>"Title 1" AND :category "1" >> >>Thanks in advance for any suggestions. >> >> >> > validates_uniqueness_of :title, :scope => "category" > > Cheers > > Matthias OesterleDamn that''s cool. Thanks a lot. -- Posted via http://www.ruby-forum.com/.