|
|
|
<?php
|
|
|
|
|
|
|
|
namespace tests\models;
|
|
|
|
|
|
|
|
use lhs\Yii2SaveRelationsBehavior\SaveRelationsBehavior;
|
|
|
|
|
|
|
|
class ProjectNoTransactions extends \yii\db\ActiveRecord
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
public static function tableName()
|
|
|
|
{
|
|
|
|
return 'project';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
public function behaviors()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'saveRelations' => [
|
|
|
|
'class' => SaveRelationsBehavior::className(),
|
|
|
|
'relations' => ['company', 'users', 'links']
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
public function rules()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
[['name', 'company_id'], 'required'],
|
|
|
|
[['name'], 'unique', 'targetAttribute' => ['company_id', 'name']],
|
|
|
|
[['company', 'users', 'links'], 'safe']
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return \yii\db\ActiveQuery
|
|
|
|
*/
|
|
|
|
public function getCompany()
|
|
|
|
{
|
|
|
|
return $this->hasOne(Company::className(), ['id' => 'company_id']);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return \yii\db\ActiveQuery
|
|
|
|
*/
|
|
|
|
public function getProjectUsers()
|
|
|
|
{
|
|
|
|
return $this->hasMany(ProjectUser::className(), ['project_id' => 'id']);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return \yii\db\ActiveQuery
|
|
|
|
*/
|
|
|
|
public function getUsers()
|
|
|
|
{
|
|
|
|
return $this->hasMany(User::className(), ['id' => 'user_id'])->via('projectUsers');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return \yii\db\ActiveQuery
|
|
|
|
*/
|
|
|
|
public function getProjectLinks()
|
|
|
|
{
|
|
|
|
return $this->hasMany(ProjectLink::className(), ['project_id' => 'id']);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return \yii\db\ActiveQuery
|
|
|
|
*/
|
|
|
|
public function getLinks()
|
|
|
|
{
|
|
|
|
return $this->hasMany(Link::className(), ['language' => 'language', 'name' => 'name'])->via('projectLinks');
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|