|
|
|
<?php
|
|
|
|
|
|
|
|
namespace tests\models;
|
|
|
|
|
|
|
|
use lhs\Yii2SaveRelationsBehavior\SaveRelationsBehavior;
|
|
|
|
|
|
|
|
class UserProfile extends \yii\db\ActiveRecord
|
|
|
|
{
|
|
|
|
|
|
|
|
public $agree;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
public static function tableName()
|
|
|
|
{
|
|
|
|
return 'user_profile';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
public function behaviors()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'saveRelations' => [
|
|
|
|
'class' => SaveRelationsBehavior::className(),
|
|
|
|
'relations' => ['user'],
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
public function rules()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
[['user_id'], 'integer'],
|
|
|
|
['bio', 'required'],
|
|
|
|
[['user_id'], 'unique'],
|
|
|
|
[['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['user_id' => 'id']],
|
|
|
|
[['agree'], 'required', 'on' => 'insert'],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return ActiveQuery
|
|
|
|
*/
|
|
|
|
public function getUser()
|
|
|
|
{
|
|
|
|
return $this->hasOne(User::className(), ['id' => 'user_id']);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|