true, 'targetClass' => Product::className(), 'targetAttribute' => [ 'product_id' => 'id' ], ], [ [ 'recommend_id' ], 'exist', 'skipOnError' => true, 'targetClass' => Product::className(), 'targetAttribute' => [ 'recommend_id' => 'id' ], ], [ [ 'product_id', 'recommend_id', ], 'unique', 'targetAttribute' => [ 'product_id', 'recommend_id', ], ], ]; } /** * @inheritdoc */ public function attributeLabels() { return [ 'product_id' => Yii::t('catalog', 'Product ID'), 'recommend_id' => Yii::t('catalog', 'Recommend ID'), ]; } /** * @return \yii\db\ActiveQuery */ public function getProduct() { return $this->hasOne(Product::className(), [ 'id' => 'product_id' ]) ->inverseOf('productRecommends'); } /** * @return \yii\db\ActiveQuery */ public function getRecommend() { return $this->hasOne(Product::className(), [ 'id' => 'recommend_id' ]); } }