true, 'targetClass' => ProductVariant::className(), 'targetAttribute' => [ 'product_variant_id' => 'id' ], ], [ [ 'stock_id' ], 'exist', 'skipOnError' => true, 'targetClass' => Stock::className(), 'targetAttribute' => [ 'stock_id' => 'id' ], ], ]; } /** * @inheritdoc */ public function attributeLabels() { return [ 'stock_id' => 'Stock ID', 'quantity' => 'Количество', 'product_variant_id' => 'Product Variant ID', 'title' => "Название", ]; } /** * @return \yii\db\ActiveQuery */ public function getProduct() { return $this->hasOne(Product::className(), [ 'id' => 'product_id' ]) ->via('variants'); } /** * @return \yii\db\ActiveQuery */ public function getProductVariant() { return $this->hasOne(ProductVariant::className(), [ 'id' => 'product_variant_id' ]); } public function getName() { return ( !empty( $this->stock ) ) ? $this->stock->title : ''; } /** * @todo Check if needed * * @param mixed $value */ public function setName($value) { $this->title = $value; } /** * @return \yii\db\ActiveQuery */ public function getStock() { return $this->hasOne(Stock::className(), [ 'id' => 'stock_id' ]); } public static function primaryKey() { return [ "stock_id", "product_variant_id", ]; } }