BBBBBB
April 27, 2006, 10:54pm
1
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.
BBBBBB
April 27, 2006, 11:05pm
2
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.
BBBBBB
April 27, 2006, 11:20pm
3
Matt R. wrote:
Rather than modifying that validation keyword, why not create your own?
Peak Obsession
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.
BBBBBB
April 28, 2006, 12:09am
4
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 Oesterle
BBBBBB
April 28, 2006, 12:30am
5
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 Oesterle
Damn that’s cool. Thanks a lot.