guild/common/models/Manager.php

73 lines
1.4 KiB
PHP
Raw Normal View History

2021-11-16 13:14:28 +03:00
<?php
namespace common\models;
use Yii;
2021-11-22 15:34:46 +03:00
use yii\db\ActiveQuery;
2021-11-16 13:14:28 +03:00
/**
* 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',
2021-11-17 12:24:02 +03:00
'user_id' => 'Пользователь',
2021-11-16 13:14:28 +03:00
];
}
2021-11-22 15:34:46 +03:00
public function beforeDelete()
{
foreach ($this->managerEmployees as $employee){
$employee->delete();
}
return parent::beforeDelete();
}
2021-11-16 13:14:28 +03:00
/**
2021-11-22 15:34:46 +03:00
* @return ActiveQuery
2021-11-16 13:14:28 +03:00
*/
public function getUser()
{
return $this->hasOne(User::className(), ['id' => 'user_id']);
}
/**
2021-11-22 15:34:46 +03:00
* @return ActiveQuery
2021-11-16 13:14:28 +03:00
*/
public function getManagerEmployees()
{
return $this->hasMany(ManagerEmployee::className(), ['manager_id' => 'id']);
}
}