<?php

namespace common\models;

/**
 * This is the model class for table "{{%USER_IMMIGRANT}}".
 *
 * @property string ID
 * @property string user_id 用户ID
 * @property string before_country_id 移民前国家ID
 * @property string after_country_id 移民后国家ID
 * @property int period_num 期数
 * @property int created_at 创建时间
 * @property string created_by 创建人
 */
class UserImmigrant extends \common\components\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return '{{%USER_IMMIGRANT}}';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['user_id', 'before_country_id', 'after_country_id', 'period_num'], 'required'],
            [['period_num'], 'number'],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'ID' => 'ID',
            'user_id' => '用户ID',
            'before_country_id' => '移民前国家ID',
            'after_country_id' => '移民后国家ID',
            'period_num' => '期数',
            'created_at' => '创建时间',
            'created_by' => '创建人',
        ];
    }

    public function beforeCountry()
    {
        return $this->hasOne(Countries::class, ['ID' => 'before_country_id']);
    }

    public function afterCountry()
    {
        return $this->hasOne(Countries::class, ['ID' => 'after_country_id']);
    }

    public function member()
    {
        return $this->hasOne(User::class, ['ID' => 'user_id']);
    }

    public function creater()
    {
        return $this->hasOne(User::class, ['ID' => 'created_by']);
    }
}
