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.
Requirements ¶
Created and tested with Yii 1.1.9 and MySQL. Feel free to adapt it for other database engines.
Usage ¶
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(
array('id', 'ext.validators.EUniqueIndexValidator'),
);
SQL Error
Can you remove the curly braces from the sql? they are throwing an error.
On line 91
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.