You really need 3 tables (so an extra model for the pivot table), but as soon as you get it, you can actually use the regular yii relationship.
For example, my project has a many-to-many relationship between purchase and transaction (please donβt ask why :)). Thus, there is a purchase model, a transaction model, and a PurchaseToTransaction model that establishes the relationship between them. I can simply execute the $ oPurchase-> transactions, and Yii will handle the many-to-many part using the relation, it is defined as follows:
'transactions' => array(self::MANY_MANY, 'Transaction', 'PurchaseToTransaction(purchaseId, transactionId)')
Note that the same applies for transactions, but vice versa:
'purchases' => array(self::MANY_MANY, 'Purchase', 'PurchaseToTransaction(transactionId, purchaseId)'),
, $oPurchase- > $oTransaction- > Yii.
" ", ( , , ).