How do I work with many-to-many relations in Yii2
问题 For example in one-to-many due to documentation (http://www.yiiframework.com/doc-2.0/guide-db-active-record.html#relational-data) you can link two models in this way (one-many = company-zone) : $defaultZone = new Zone; $defaultZone->name = Zone::DEFAULT_ZONE; $company->link('zones', $defaultZone); But how it works for many-to-many relations when you have transit table like tbl_user_market(user_id, market_id) ? 回答1: When using a junction table for many-to-many relations, you have to Define the