This validator will extract the unique indexes from a table and will test the values against them. Each index will generate proper errors if the unique index is violated.
Created and tested with Yii 1.1.9 and MySQL. Feel free to adapt it for other database engines.
Extract the file to a folder. Example: 'protected/extensions/validators'. Add the validator to your model's rules.
Note: Since this validator will check all the model's attributes instead of a particular one, the 'attribute' parameter of the rule is not taken into account.
If the index is multicolumn, the validator will throw the error to the primaryKey attribute of the model, and will throw empty string errors to each of the attributes in order to mark them in red. It's better to use form's errorSummary to display all the errors. If the index is single column, the validator will throw the error to the attribute.
$rules = array(