true, 'targetClass' => Category::className(), 'targetAttribute' => [ 'category_id' => 'id' ], ], [ [ 'product_id' ], 'exist', 'skipOnError' => true, 'targetClass' => Product::className(), 'targetAttribute' => [ 'product_id' => 'id' ], ], ]; } /** * @inheritdoc */ public function attributeLabels() { return [ 'product_id' => Yii::t('product', 'Product'), 'category_id' => Yii::t('product', 'Category'), ]; } public function getCategory() { return $this->hasOne(Category::className(), [ 'id' => 'category_id' ]); } public function getProduct() { return $this->hasOne(Product::className(), [ 'id' => 'product_id' ]); } }