Пример #1
0
 public function getProductsCategories()
 {
     return $this->hasMany(Categories::className(), ['id' => 'category_id'])->viaTable(CategoryProduct::tableName(), ['product_id' => 'id']);
 }
Пример #2
0
 public function getSelectedArray($product_id)
 {
     $query = (new Query())->from(CategoryProduct::tableName())->where(['product_id' => $product_id]);
     $items = [];
     foreach ($query->all($this->db) as $row) {
         $items[] = (int) $row['category_id'];
     }
     return $items;
 }