php - yii2 hasOne relation work wrong -
i have 2 tables : users , favorite following :
now establish relation between them following in favorite model
public function getuser() { return $this->hasone(user::classname(), ['id', 'user_favorited']); }
in controller find list of user's favorites
public function actiongetlist() { $favorite = favorite::find()->where([ 'user_favoriting' => yii::$app->user->id ])->all(); foreach ($favorite $key => $item) { # code... echo "<pre>"; var_dump($item->user); echo "<br/>"; die('123'); } return $favorite; }
but when make request action error
column not found: 1054 unknown column '0' in 'where clause'\nthe sql being executed was: select * `users` (`0`, `1`) in ((12, 80))",
please me!
according documentation have use:
public function getuser() { return $this->hasone(user::classname(), ['id' => 'user_favorited']); }
Comments
Post a Comment