Suppose you have a ‘families’ table in your database with a ‘husband’ and ‘wife’ column. You add a a composite key so that the combination husband and wife is unique. You certainly don't want another record with the same husband and wife combination. At the database level your migration could look like this:
Validations in Rails 2.x
Now you want to add a corresponding validation in your family model. In Rails 2.x we can use a scope:
Validations in Rails 3
In Rails 3 this looks slightly different:
I wouldn't have found this without the help of KandadaBoggu and epochwolf on the stackoverflow forum, thanks guys!