<?php
    
    namespace common\models;
    
    use common\modules\language\models\Language;
    use Yii;
    use yii\db\ActiveRecord;
    
    /**
     * This is the model class for table "orders_delivery_lang".
     * @property integer  $orders_delivery_id
     * @property integer  $language_id
     * @property string   $title
     * @property string   $text
     * @property Language $language
     * @property Delivery $delivery
     */
    class OrdersDeliveryLang extends ActiveRecord
    {
        
        /**
         * @inheritdoc
         */
        public static function primaryKey()
        {
            return [
                'orders_delivery_id',
                'language_id',
            ];
        }
        
        /**
         * @inheritdoc
         */
        public static function tableName()
        {
            return 'orders_delivery_lang';
        }
        
        /**
         * @inheritdoc
         */
        public function rules()
        {
            return [
                [
                    [
                        'title',
                        'text',
                    ],
                    'required',
                ],
                [
                    [ 'text' ],
                    'string',
                ],
                [
                    [ 'title' ],
                    'string',
                    'max' => 255,
                ],
                [
                    [
                        'orders_delivery_id',
                        'language_id',
                    ],
                    'unique',
                    'targetAttribute' => [
                        'orders_delivery_id',
                        'language_id',
                    ],
                    'message'         => 'The combination of Orders Delivery ID and Language ID has already been taken.',
                ],
                [
                    [ 'language_id' ],
                    'exist',
                    'skipOnError'     => true,
                    'targetClass'     => Language::className(),
                    'targetAttribute' => [ 'language_id' => 'language_id' ],
                ],
                [
                    [ 'orders_delivery_id' ],
                    'exist',
                    'skipOnError'     => true,
                    'targetClass'     => Delivery::className(),
                    'targetAttribute' => [ 'orders_delivery_id' => 'id' ],
                ],
            ];
        }
        
        /**
         * @inheritdoc
         */
        public function attributeLabels()
        {
            return [
                'orders_delivery_id' => Yii::t('app', 'orders_delivery_id'),
                'language_id'        => Yii::t('app', 'language_id'),
                'title'              => Yii::t('app', 'title'),
                'text'               => Yii::t('app', 'text'),
            ];
        }
        
        /**
         * @return \yii\db\ActiveQuery
         */
        public function getLanguage()
        {
            return $this->hasOne(Language::className(), [ 'language_id' => 'language_id' ]);
        }
        
        /**
         * @return \yii\db\ActiveQuery
         */
        public function getDelivery()
        {
            return $this->hasOne(Delivery::className(), [ 'id' => 'orders_delivery_id' ]);
        }
    }
