A validator that validates that a multi-column value is unique
A validator that validates that a multi-column value is unique
The installation of this library is made via composer.
Download composer.phar
from their website.
Then add to your composer.json :
"require": {
...
"yii1-extended/yii1-multiple-unique-validator": "^1",
...
}
Then run php composer.phar update
to install this library.
The autoloading of all classes of this library is made through composer's autoloader.
In the model validation :
public function rules()
{
return array(
...
array('<attribute names>', 'CMultipleUniqueValidator', 'attributeList' => array(
'<attribute1>', '<attribute2>', ...
)),
...
);
}
This validator validates that the given attribute tuple is unique. For example,
if we have an unique index (or primary key) on the fields ("field1", "field2,
"field3"), then this validator will ensure that the values represented by
($model->field1
, $model->field2
, $model->field3
) is unique into the
related table of the database.
If no attributeList is provided, or only one field is present, this validator
falls back on the CUniqueValidator
which is a core validator.
MIT (See license file).