['company_id', 'user_card_id'], 'message'=>'Этот менеджер уже закреплён за компанией'], [['company_id'], 'exist', 'skipOnError' => true, 'targetClass' => Company::className(), 'targetAttribute' => ['company_id' => 'id']], [['user_card_id'], 'exist', 'skipOnError' => true, 'targetClass' => UserCard::className(), 'targetAttribute' => ['user_card_id' => 'id']], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => 'ID', 'company_id' => 'Компания', 'user_card_id' => 'Менеджер', ]; } /** * @return \yii\db\ActiveQuery */ public function getCompany() { return $this->hasOne(Company::className(), ['id' => 'company_id']); } /** * @return \yii\db\ActiveQuery */ public function getUserCard() { return $this->hasOne(UserCard::className(), ['id' => 'user_card_id']); } public static function getManagersByCompany($company_id): array { return self::find()->where(['company_id' => $company_id])->all(); } public static function getName($id) { return self::findOne($id)->userCard->fio; } }