Yii::$app->user->identity->id]); // $this->user_card_id = $user_card->id; // return parent::beforeSave($insert); // } public function beforeValidate() { if (empty($this->user_card_id)) { $user_card = UserCard::findOne(['id_user' => Yii::$app->user->identity->id]); $this->user_card_id = $user_card->id; } return parent::beforeValidate(); } }