<?php namespace common\models; use Yii; /** * This is the model class for table "tb_person". * * @property integer $user_id * @property string $firstname * @property string $lastname * @property string $photo * @property integer $tb_department_id * * @property TbDepartment $tbDepartment * @property User $user */ class Person extends \yii\db\ActiveRecord { public $person_img; /** * @inheritdoc */ public static function tableName() { return 'tb_person'; } /** * @inheritdoc */ public function rules() { return [ [['user_id', 'firstname', 'lastname', 'tb_department_id'], 'required'], [['user_id', 'tb_department_id'], 'integer'], [['firstname', 'lastname', 'photo'], 'string', 'max' => 100], [['tb_department_id'], 'exist', 'skipOnError' => true, 'targetClass' => Department::className(), 'targetAttribute' => ['tb_department_id' => 'id']], [['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['user_id' => 'id']], [['person_img'],'file','skipOnEmpty' => true, 'on' => 'update', 'extensions' => 'jpg,png,gif'] ]; } /** * @inheritdoc */ public function attributeLabels() { return [ 'user_id' => 'User ID', 'firstname' => 'ชื่อ', 'lastname' => 'นามสกุล', 'photo' => 'รูปภาพ', 'tb_department_id' => 'โครงการ', 'person_img' => 'รูปภาพ', ]; } /** * @return \yii\db\ActiveQuery */ public function getDepartment() { // return $this->HAS_MANY(Department::className(), ['id' => 'tb_department_id']); return $this->hasOne(Department::className(), ['id' => 'tb_department_id']); } /** * @return \yii\db\ActiveQuery */ public function getUser() { return $this->hasOne(User::className(), ['id' => 'user_id']); //ความสมพันธ์ 1:1 } }