<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "order_address".
 *
 * @property integer $id
 * @property integer $order_id
 * @property integer $province
 * @property integer $city
 * @property integer $district
 * @property integer $town
 * @property string $address
 * @property string $created_at
 * @property string $updated_at
 */
class OrderAddress extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'order_address';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['order_id', 'province', 'city', 'district', 'town'], 'integer'],
            [['address'], 'string', 'max' => 120],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'order_id' => 'Order ID',
            'province' => 'Province',
            'city' => 'City',
            'district' => 'District',
            'town' => 'Town',
            'address' => 'Address',
        ];
    }

    public function getRegionP()
    {
        return $this->hasOne(Region::className(), ['id' => 'province']);
    }
    public function getRegionC()
    {
        return $this->hasOne(Region::className(), ['id' => 'city']);
    }
    public function getRegionD()
    {
        return $this->hasOne(Region::className(), ['id' => 'district']);
    }
    public function getRegionT()
    {
//        dd($this->town);
        if($this->town){
            return $this->hasOne(Region::className(), ['id' => 'town']);
        }else{
            $string='';
            return $string;
        }

    }
}