M
M
My joy2018-02-02 15:08:02
Yii
My joy, 2018-02-02 15:08:02

How to search for 2 fields at once in Exist Validator?

Hi friends!
There is a need to check the existence of a record in the database during validation, but only look for not one field in the table, but two. Can this be done using the standard exist-validator methods?
Now it looks like this:

['zip', 'exist', 'targetClass' => ZipKz::className(), 'targetAttribute' => 'zip_new', 'when' => function($model){
  return $model->geo == 'KZ';
}],

Those. the zip field is checked in the index table, and in this table there are 2 columns (zip_new, zip_old), and you need to look for a match on both.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
OKyJIucT, 2018-02-02
@OKyJIucT

www.yiiframework.com/doc-2.0/yii-validators-existv...

['zip', 'exists', 'targetClass' => ZipKz::className(), 'targetAttribute' => ['zip_old', 'zip_new'], 'when' => function($model){
  return $model->geo == 'KZ';
}],

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question