Merge pull request #7 from vahan-garnikyan/contrib

ProfileQuery bug fix: search for profile by user_id instead profile id
This commit is contained in:
Antonio Ramirez
2017-02-11 17:10:50 +01:00
committed by GitHub
2 changed files with 10 additions and 1 deletions

View File

@ -104,7 +104,7 @@ class SettingsController extends Controller
public function actionProfile() public function actionProfile()
{ {
$profile = $this->profileQuery->whereId(Yii::$app->user->identity->getId())->one(); $profile = $this->profileQuery->whereUserId(Yii::$app->user->identity->getId())->one();
if ($profile === null) { if ($profile === null) {
$profile = $this->make(Profile::class); $profile = $this->make(Profile::class);

View File

@ -19,4 +19,13 @@ class ProfileQuery extends ActiveQuery
{ {
return $this->andWhere(['id' => $id]); return $this->andWhere(['id' => $id]);
} }
/**
* Search by user id
* @return ActiveQuery
*/
public function whereUserId($user_id)
{
return $this->andWhere(['user_id' => $user_id]);
}
} }