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.

132 lines
3.0 KiB

9 years ago
<?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' => [
9 years ago
'class' => SaveRelationsBehavior::className(),
'relations' => [
'company',
'users',
'contacts',
6 years ago
'images',
'links' => ['scenario' => Link::SCENARIO_FIRST],
'projectLinks' => ['cascadeDelete' => true],
'tags' => [
'extraColumns' => function ($model) {
/** @var $model Tag */
return [
'order' => $model->order
];
}
]
],
9 years ago
],
];
}
/**
* @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
9 years ago
*/
public function getCompany()
{
return $this->hasOne(Company::className(), ['id' => 'company_id']);
}
/**
* @return \yii\db\ActiveQuery
9 years ago
*/
public function getProjectUsers()
{
return $this->hasMany(ProjectUser::className(), ['project_id' => 'id']);
}
/**
* @return \yii\db\ActiveQuery
9 years ago
*/
public function getUsers()
{
return $this->hasMany(User::className(), ['id' => 'user_id'])->via('projectUsers', function ($query) {
return $query;
});
9 years ago
}
/**
* @return \yii\db\ActiveQuery
9 years ago
*/
public function getProjectLinks()
{
return $this->hasMany(ProjectLink::className(), ['project_id' => 'id']);
}
/**
* @return \yii\db\ActiveQuery
9 years ago
*/
public function getContacts()
{
return $this->hasMany(ProjectContact::className(), ['project_id' => 'id']);
}
/**
* @return \yii\db\ActiveQuery
*/
6 years ago
public function getImages()
{
return $this->hasMany(ProjectImage::className(), ['project_id' => 'id']);
}
/**
* @return \yii\db\ActiveQuery
*/
9 years ago
public function getLinks()
{
return $this->hasMany(Link::className(), ['language' => 'language', 'name' => 'name'])->via('projectLinks');
}
/**
* @return ActiveQuery
*/
public function getTags()
{
return $this->hasMany(Tag::className(), ['id' => 'tag_id'])->viaTable('project_tags', ['project_id' => 'id']);
}
9 years ago
}