Hi.
I have problem with form validation on model update/edit. For example; i wont edit user (id = 99, email = [email protected]). On "users" model, validation code looks like this:
$validator->add(['email', 'date_deleted'], new UniquenessValidator([
'convert' => function ($data) {
$data['email'] = $this->getDI()->get('filter')->sanitize($data['email'], 'trim');
$data['email'] = $this->getDI()->get('filter')->sanitize($data['email'], 'email');
$data['email'] = $this->getDI()->get('filter')->sanitize($data['email'], 'lower');
return $data;
},
'message' => 'duplicate entry for ":fields" field on Users model'
])
);
And execudet query from validation looks:
SELECT COUNT(*) AS `rowcount` FROM `somedb`.`users` WHERE `users`.`email` = "[email protected]" AND `users`.`date_deleted` IS NULL AND `users`.`id` <> 99
Is ok. But i have validation in form:
$emailElement->addValidators([
// ... PresenceOfValidator, EmailValidator...
new UniquenessValidator([
'model' => new UsersModel, // or $this->getEntity()
'fields' => ['email', 'date_deleted'],
'convert' => function ($data) {
$data['email'] = $this->filter->sanitize($data['email'], 'trim');
$data['email'] = $this->filter->sanitize($data['email'], 'email');
$data['email'] = $this->filter->sanitize($data['email'], 'lower');
return $data;
},
'message' => 'Entered e-mail address is currently in use by another user.'
]);
Executed validation from form query looks:
SELECT COUNT(*) AS `rowcount` FROM `somedb`.`users` WHERE `users`.`email` = "[email protected]" AND `users`.`date_deleted` IS NULL
In form validation, id of entity is skipped and edited user email is not unique, because is used by self.
How to user uniqueness validator on form, to get the same result in case model-side validation?
Phalcon v3.3.2