<?php

namespace common\modules\product\models;

use common\modules\relation\models\Relation;
use common\modules\rubrication\models\TaxOption;
use Yii;

/**
 * This is the model class for table "{{%product_category}}".
 *
 * @property integer $product_id
 * @property integer $category_id
 *
 * @property TaxOption $devCategory
 */
class ProductCategory extends Relation
{
    public $alias = 'product_categories';

    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'product_category';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['product_id', 'category_id'], 'integer'],
            [['category_id'], 'exist', 'skipOnError' => true, 'targetClass' => Category::className(), 'targetAttribute' => ['category_id' => 'category_id']],
            [['product_id'], 'exist', 'skipOnError' => true, 'targetClass' => Product::className(), 'targetAttribute' => ['product_id' => 'product_id']],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'product_id' => Yii::t('product', 'Product'),
            'category_id' => Yii::t('product', 'Category'),
        ];
    }

    public function getProduct() {
        return $this->getEntity1();
    }

    public function getCategory() {
        return $this->getEntity2();
    }
}
