Hasmany In Yii2?

The situation is as follows: Realized as a functional "friends" for users. I have two tables User, UserContact.


User

`id` int(11) NOT NULL AUTO_INCREMENT,

`login` varchar(60) COLLATE utf8_unicode_ci NOT NULL,

`email` varchar(60) COLLATE utf8_unicode_ci NOT NULL,

PRIMARY KEY (`id`),


UserContact

`u_id1` int(11) NOT NULL,

`u_id2` int(11) NOT NULL,

PRIMARY KEY (`u_id1`,`u_id2`),

KEY `fk_user_contact_user_2` (`u_id2`)

Ie, each user has a lot of friends, just like other people have a lot of friends, a many-to-many.

How to describe this in svzya Yii2? At the moment I use this code, but it is not correct, because the search is only u_id2.


return $this->hasMany(User::className(), ['id' => 'u_id2'])->viaTable(

UserContact::tableName(),

['u_id1' => 'id'],

function ($query) use ($status) {

$query->where(['status' => $status]);

}

);

For example: u_id1 = 1, u_id2 = 2, status = 0 Communication is, but when another user (c u_id2) comes and starts looking for the request, nothing is as it searches in u_id1 your ID. As necessary to u_id1 and u_id2 could find yourself in the records: u_id1 = 1, u_id2 = 2, status = 0