validates_uniqueness w scope

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