<?php

namespace common\models;

use common\modules\language\models\Language;
use Yii;

/**
 * This is the model class for table "product_spec_lang".
 *
 * @property integer $product_spec_id
 * @property integer $language_id
 * @property string $tech_spec_text
 * @property string $instruction
 *
 * @property Language $language
 * @property ProductSpec $productSpec
 */
class ProductSpecLang extends \yii\db\ActiveRecord
{
    
    public static function primaryKey()
    {
        return [
            'product_spec_id',
            'language_id',
        ];
    }
    
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'product_spec_lang';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['tech_spec_text', 'instruction'], 'string'],
            [['product_spec_id', 'language_id'], 'unique', 'targetAttribute' => ['product_spec_id', 'language_id'], 'message' => 'The combination of Product Spec ID and Language ID has already been taken.'],
            [['language_id'], 'exist', 'skipOnError' => true, 'targetClass' => Language::className(), 'targetAttribute' => ['language_id' => 'language_id']],
            [['product_spec_id'], 'exist', 'skipOnError' => true, 'targetClass' => ProductSpec::className(), 'targetAttribute' => ['product_spec_id' => 'product_spec_id']],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'product_spec_id' => Yii::t('app', 'product_spec_id'),
            'language_id' => Yii::t('app', 'language_id'),
            'tech_spec_text' => Yii::t('app', 'tech_spec_text'),
            'instruction' => Yii::t('app', 'instruction'),
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getLanguage()
    {
        return $this->hasOne(Language::className(), ['language_id' => 'language_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getProductSpec()
    {
        return $this->hasOne(ProductSpec::className(), ['product_spec_id' => 'product_spec_id']);
    }
}
