yii2 - find many to many relationship objects

yii2
voted: 0
vote
yii2 php frameworks activerecord

For example. Product can have many tags. Product tags can be found with this active record query:

table structure:

table: Product
-   id

table: Tag
-   id
-   name

table:  Product_tag
-   id
- product_id
- tag_id

<?php
$currentTags = Tag::find()->innerJoin('product_tag', 'tag.id = product_tag.tag_id')->where(['product_id' => $model->id])->all();
?>
working url: not entered
version: 2

Leave a Comment:
Characters left:
No comments yet.