Answer the question
In order to leave comments, you need to log in
How to select user from related table with condition (hasOne)?
in this entry writes the user id from the user table to the user_id field of the profile table.
public function getUser()
{
return $this->hasOne($this->module->manager->userClass, ['id' => 'user_id']);
}
Answer the question
In order to leave comments, you need to log in
public function afterSave($insert, $changedAttributes)
{
if ($insert && $this->role_id === 2) {
$profile = $this->module->manager->createProfile([
'user_id' => $this->id,
'gravatar_email' => $this->email
]);
$profile->save(false);
}
parent::afterSave($insert, $changedAttributes);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question