How can I 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 such a pair is 1 and 2, as well as whether there is a pair of 2 and 1
How to implement it? Normal unique validator will not help you to write your own?
July 8th 19 at 16:08
2 answers
July 8th 19 at 16:10
Maybe something like this,
 ['user_id', 'invite_id'],
 'targetAttribute' => ['user_id', 'invite_id'],
 'filter' => [
 ['user_id' => $this->invite_id],
 ['invite_id' => $this->user_id],
haven't checked how it works, found at the docks filter. thank you. Have done so:
[['user_id', 'invite_id'], 'unique','targetAttribute' => ['user_id', 'invite_id'], 'filter'=>function($query){return $query->orWhere(['and',['user_id'=>$this->invite_id], ['invite_id'=>$this->user_id]]);}],
- Henderson_Beat commented on July 8th 19 at 16:13
July 8th 19 at 16:12
ExistValidator not?
The same as unique, the issue was in the record. Already suggested about the filter - Henderson_Beat commented on July 8th 19 at 16:15

Find more questions by tags ValidationYii