Let’s say you have a table and you want to do the equivalent of creating a muli-column key. In other words, you want to make sure that the combination of values of multiple columns is unique.
This is not explicitly obvious in Rails, but it is directly supported.
If you have an animals table and want to ensure that there are no records with duplicate kind and color columns, you do this:
validates_uniqueness_of :kind, :scope => [:color]
It’s not important which column names appear in the scope vs. the main section of the statement.