[ 'class' => SaveRelationsBehavior::className(), 'relations' => ['company', 'users', 'links'] ], ]; } /** * @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 ActiveQuery */ public function getCompany() { return $this->hasOne(Company::className(), ['id' => 'company_id']); } /** * @return ActiveQuery */ public function getProjectUsers() { return $this->hasMany(ProjectUser::className(), ['project_id' => 'id']); } /** * @return ActiveQuery */ public function getUsers() { return $this->hasMany(User::className(), ['id' => 'user_id'])->via('projectUsers'); } /** * @return ActiveQuery */ public function getProjectLinks() { return $this->hasMany(ProjectLink::className(), ['project_id' => 'id']); } /** * @return ActiveQuery */ public function getLinks() { return $this->hasMany(Link::className(), ['language' => 'language', 'name' => 'name'])->via('projectLinks'); } }