Hi there
I have the unique composite key in the table, consists of fields ('position', 'controller', 'action')
In the model I registered:
public function validation() {
$validator = new Phalcon\Validation();
$validator->add(
[
"position",
"controller",
"action",
],
new Phalcon\Validation\Validator\Uniqueness()
);
return $this->validate($validator);
}
Validation of a composite key does not work. Displays:
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '1-admin_access-' for key 'position_controller_action'
Apparently for each field separately checks and not on all together. How do I validate a composite key in a model?
The solution from this topic is NOT appropriate: https://forum.phalcon.io/discussion/4205/phalcon-model-validate-uniqueness-by-two-fields
public function validation()
{
$this->validate(new Uniqueness(array(
'field' => array('email', 'name')
)));
}
Not suitable, because the Validate method should accept \ Phalcon \ ValidationInterface which in turn takes validation rules via the method:
public function add($field, \Phalcon\Validation\ValidatorInterface $validator) {}
How do I validate a unique composite key in the model?