ProductLang.php 1.81 KB
<?php

namespace common\models;

use artbox\core\models\Language;
use yii\db\ActiveRecord;

class ProductLang extends ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'product_lang';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [
                [
                    'product_id',
                    'language_id',
                    'title',
                ],
                'required',
            ],
            [
                [
                    'product_id',
                    'language_id',
                ],
                'integer',
            ],
            [
                [
                    'title',
                ],
                'string',
                'max' => 255,
            ],
            [
                [
                    'description',
                ],
                'string',
            ],
            [
                [ 'language_id' ],
                'exist',
                'skipOnError'     => true,
                'targetClass'     => Language::className(),
                'targetAttribute' => [ 'language_id' => 'id' ],
            ],
            [
                [ 'product_id' ],
                'exist',
                'skipOnError'     => true,
                'targetClass'     => Product::className(),
                'targetAttribute' => [ 'product_id' => 'id' ],
            ],
        ];
    }


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

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getProduct()
    {
        return $this->hasOne(Product::className(), [ 'id' => 'product_id' ]);
    }
}