Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

validates_uniqueness_of scoped to multiple columns

When using Validates_uniqueness_of with the :scope option, is it valid to pass an array of columns like this:

validates_uniqueness_of :x, :scope => [:y, :z] 

As I want :x to be unique in the context of both :y and :z If not then how could you achieve this? 2 validations one for each scope?

Thanks

like image 310
Cameron Avatar asked Jun 25 '09 13:06

Cameron


1 Answers

Yes, it's valid and your syntax is exactly the way to achieve it. See the validations documentation page for more details.

like image 145
mikej Avatar answered Sep 18 '22 14:09

mikej