Forum: Ruby on Rails Validate uniqueness of category model depending on user model

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Geekyra (Guest)
on 2009-02-18 10:29
(Received via mailing list)
How to make unique validation on category model that is belong to user
model and the unique validation must depend on user model so for
example every user may have their own unique category name but two or
more user may have a same category name but they can't have a same
category name twice.
MaD (Guest)
on 2009-02-18 10:33
(Received via mailing list)
could you give an example to explain that a little bit more?
Frederick C. (Guest)
on 2009-02-18 10:38
(Received via mailing list)
On Feb 18, 8:28 am, Geekyra <removed_email_address@domain.invalid> wrote:
> How to make unique validation on category model that is belong to user
> model and the unique validation must depend on user model so for
> example every user may have their own unique category name but two or
> more user may have a same category name but they can't have a same
> category name twice.

Use the :scope option on validates_uniqueness_of ?

Fred
Geekyra (Guest)
on 2009-02-19 10:24
(Received via mailing list)
For example : (note: change category into product for easier
understanding)
There are 2 user :
"User 1" may have product name it "CAR", "HOUSE", "HOUSE@XXX"
"User 2" may have product name it "CAR", "CAR 2", "HOUSE@YYY",
"HOUSE", "WALLET"

The point is every user may have a same product but they need to
maintain a user uniqueness product so "User 1" can't have a new
product name "CAR" cos it's already have it on the first row product.

I will try to look forward for Frederick suggestion, see if
using :scope solve the problem. Thanks for Frederick
This topic is locked and can not be replied to.