Answer the question
In order to leave comments, you need to log in
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
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],
]
],
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question