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.
93 lines
1.9 KiB
93 lines
1.9 KiB
<?php |
|
|
|
namespace tests\models; |
|
|
|
use lhs\Yii2SaveRelationsBehavior\SaveRelationsBehavior; |
|
|
|
class Project extends \yii\db\ActiveRecord |
|
{ |
|
/** |
|
* @inheritdoc |
|
*/ |
|
public static function tableName() |
|
{ |
|
return 'project'; |
|
} |
|
|
|
/** |
|
* @inheritdoc |
|
*/ |
|
public function behaviors() |
|
{ |
|
return [ |
|
'saveRelations' => [ |
|
'class' => SaveRelationsBehavior::className(), |
|
'relations' => ['company', 'users', 'links' => ['scenario' => Link::SCENARIO_FIRST]] |
|
], |
|
]; |
|
} |
|
|
|
/** |
|
* @inheritdoc |
|
*/ |
|
public function rules() |
|
{ |
|
return [ |
|
[['name', 'company_id'], 'required'], |
|
[['name'], 'unique', 'targetAttribute' => ['company_id', 'name']], |
|
]; |
|
} |
|
|
|
/** |
|
* @inheritdoc |
|
*/ |
|
public function transactions() |
|
{ |
|
return [ |
|
self::SCENARIO_DEFAULT => self::OP_ALL, |
|
]; |
|
} |
|
|
|
/** |
|
* @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', function ($query) { |
|
return $query; |
|
}); |
|
} |
|
|
|
/** |
|
* @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'); |
|
} |
|
|
|
} |