简体   繁体   中英

How can I get table via hasMany in Yii2?

Using Yii2. I have a tables:

User

(id)

and

UserContacts

(u_id1, u_id2).

In model action:

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

Prompt how can I get a table with users through viaTable ()?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM