Validates_uniqueness w scope

In a one-to-many relationship (domain has_many :categories and
category belongs_to :domain)

In the category model I use:
validates_uniqueness_of :name, :case_sensitive => false

but upon creation of a category this validation is performed on ALL
domains,
can I restrict it only to the categories of the current domain, the to
which teh category being saved belongs_to ? if yes ? how ?

thanks for your help

Kad,

You can use scope on the foreign key:

validates_uniqueness_of :name, :scope => :domain_id

http://api.rubyonrails.com/classes/ActiveRecord/Validations/ClassMethods.html#M000816

Alain R. wrote:

Kad,

You can use scope on the foreign key:

validates_uniqueness_of :name, :scope => :domain_id

Peak Obsession

thanks a lot… I apologize, I should had look it before…