validates_uniqueness_of has a :scope option that works like
validates_uniqueness_of :interest, :scope => :user
but I''m not sure how this works with HABTM relationships or where you
would
put the validation. Perhaps in the User model you could put the validation
above.
On 5/10/06, Bonicon <antins@hotmail.com> wrote:>
> Hello,
>
> I am new to Ruby on rails and this is therefore probably trivial. Lets
> say I have 3 tables - users[id,name, age, ...],
> interests[id,name,description, ...], and finally a table
> user_interests[id,user_id,interest_id] to link a user to a set of
> interests. Now there is no problem to put validates_uniqueness_of :name
> in the user-model to ensure that I only have one Lenny, but how do I
> validate the uniqueness of Lenny''s interests in the
user_interest-table?
> Ie, is there a method to validate that an entry into a table is unique
> in terms of several fields? Lenny -fishing, Lenny - programming OK,
> whereas Lenny - fishing, Lenny - fishing would be caught?
>
>
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://wrath.rubyonrails.org/pipermail/rails/attachments/20060510/1eebbc07/attachment.html