From 797849e6a33274bf0da29a2985285995f3693561 Mon Sep 17 00:00:00 2001 From: Alban Jubert Date: Sun, 8 May 2016 16:02:21 +0200 Subject: [PATCH] Add missing ProjectNoTransactions model test class --- README.md | 2 + tests/models/ProjectNoTransactions.php | 81 ++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 tests/models/ProjectNoTransactions.php diff --git a/README.md b/README.md index 61bd025..fbf3a33 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,8 @@ use lhs\Yii2SaveRelationsBehavior\SaveRelationsBehavior; class Project extends \yii\db\ActiveRecord { + use SaveRelationsTrait; // Optionnal + public function behaviors() { return [ diff --git a/tests/models/ProjectNoTransactions.php b/tests/models/ProjectNoTransactions.php new file mode 100644 index 0000000..bd94c90 --- /dev/null +++ b/tests/models/ProjectNoTransactions.php @@ -0,0 +1,81 @@ + [ + 'class' => SaveRelationsBehavior::className(), + 'relations' => ['company', 'users', 'links'] + ], + ]; + } + + /** + * @inheritdoc + */ + public function rules() + { + return [ + [['name', 'company_id'], 'required'], + [['name'], 'unique', 'targetAttribute' => ['company_id', 'name']], + ]; + } + + /** + * @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'); + } + +} \ No newline at end of file