A
A
Andrey Kotosin2018-06-16 17:30:59
Yii
Andrey Kotosin, 2018-06-16 17:30:59

How to create a Yii2-user relationship with my table?

I installed Yii2-user in my project, created my own contact table which has "id", "user_id", "phone", "email", "skype", "adress", "index" columns. Interested in the question, how to link the standard table "User" from yii2-user with my table "contact"?
Those. I need to be able to contact an authorized user on the site and get his connection with the contact table (for output, editing, etc.)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim, 2018-06-16
@av_kotosin

And unless through relational communication does not approach? It needs to be added to your project model. If you have an extension, then you need to redefine identityClass to your model in the project.

'components' => [
        'user' => [
            'identityClass' => 'app\models\User',
        ],
    ],

Copy all methods from the Yii2-user extension model into this model and add the connection you need to it.
/**
     * @return \yii\db\ActiveQuery
     */
    public function getСontact()
    {
        return $this->hasOne(Сontact::className(), ['user_id' => 'id']);
    }

$model = User::find()->all();
$model->contact;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question