Consider a case of STI where:

Now try following at console:

This will let you create three records in users table with same name, validates_uniqueness_of written in User class has no effect on it. validates_uniqueness_of automatically scoped with class names, that means it will not let you create two managers with same name or two customers with same name or two users with same name.

If you want uniqueness of an attribute in overall table, put the following code in some file in your lib dir and require that file in environment:

And then use validates_overall_uniqueness_of instead of validates_uniqueness_of.

Share this: