<?php

namespace common\modules\rubrication\models;

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

/**
 * This is the model class for table "{{%tax_group_to_group}}".
 *
 * @property integer $tax_group1_id
 * @property integer $tax_group2_id
 * @property string $alias
 * @property integer $sort
 *
 * @property TaxGroup $taxGroup1
 * @property TaxGroup $taxGroup2
 */
class TaxGroupToGroup extends Relation
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'tax_group_to_group';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['tax_group1_id', 'tax_group2_id', 'alias'], 'required'],
            [['tax_group1_id', 'tax_group2_id', 'sort'], 'integer'],
            [['alias'], 'string', 'max' => 50]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'tax_group1_id' => Yii::t('app', 'Tax Group1 ID'),
            'tax_group2_id' => Yii::t('app', 'Tax Group2 ID'),
            'alias' => Yii::t('app', 'Alias'),
            'sort' => Yii::t('app', 'Sort'),
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getTaxGroup1()
    {
        return $this->hasOne(TaxGroup::className(), ['tax_group_id' => 'tax_group1_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getTaxGroup2()
    {
        return $this->hasOne(TaxGroup::className(), ['tax_group_id' => 'tax_group2_id']);
    }
}
