guild/common/models/Manager.php
2021-11-22 15:34:46 +03:00

73 lines
1.4 KiB
PHP

<?php
namespace common\models;
use Yii;
use yii\db\ActiveQuery;
/**
* This is the model class for table "manager".
*
* @property int $id
* @property int $user_id
*
* @property User $user
* @property ManagerEmployee[] $managerEmployees
*/
class Manager extends \yii\db\ActiveRecord
{
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'manager';
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['user_id'], 'integer'],
[['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['user_id' => 'id']],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'user_id' => 'Пользователь',
];
}
public function beforeDelete()
{
foreach ($this->managerEmployees as $employee){
$employee->delete();
}
return parent::beforeDelete();
}
/**
* @return ActiveQuery
*/
public function getUser()
{
return $this->hasOne(User::className(), ['id' => 'user_id']);
}
/**
* @return ActiveQuery
*/
public function getManagerEmployees()
{
return $this->hasMany(ManagerEmployee::className(), ['manager_id' => 'id']);
}
}