[ 'class' => SaveRelationsBehavior::className(), 'relations' => ['users'] ], ]; } /** * @inheritdoc */ public function rules() { return [ ['name', 'required'], ['name', 'unique', 'targetClass' => '\tests\models\Company'], ]; } /** * @return \yii\db\ActiveQuery */ public function getUsers() { return $this->hasMany(User::className(), ['company_id' => 'id']); } }