M
M
Maxim Timofeev2016-06-07 17:16:38
Yii
Maxim Timofeev, 2016-06-07 17:16:38

How to make such validation in YII2?

There are two attributes in the model "user_id" and "invite_id"
let's say equal to 1 and 2
It is necessary to check whether there is such a pair 1 and 2, and also whether there is a pair 2 and 1
How to implement this? The usual unique validator will not help here, write your own?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
polar-bear, 2016-06-07
@webinar

Perhaps something like this

[
    ['user_id', 'invite_id'],
    'unique',
    'targetAttribute' => ['user_id', 'invite_id'],
    'filter' => [
        'or',
        ['user_id' => $this->invite_id],
        ['invite_id' => $this->user_id],
    ]
],

A
Andrey, 2016-06-07
@VladimirAndreev

ExistValidator not?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question