You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.1 KiB

<?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']);
}
}