我有2个表:用户并且喜欢以下内容:
现在我在喜欢的模型
中建立了它们之间的关系public function getUser()
{
return $this->hasOne(User::className(), ['id', 'user_favorited']);
}
控制器中的我找到了用户收藏的列表
public function actionGetList()
{
$favorite = Favorite::find()->where([
'user_favoriting' => Yii::$app->user->id
])->all();
foreach ($favorite as $key => $item) {
# code...
echo "<pre>"; var_dump($item->user); echo "<br/>"; die('123');
}
return $favorite;
}
但是当我向此操作发出请求时,我收到错误
Column not found: 1054 Unknown column '0' in 'where clause'\nThe SQL being executed was: SELECT * FROM `users` WHERE (`0`, `1`) IN ((12, 80))",
请帮助我!
答案 0 :(得分:3)
根据documentation你必须使用:
public function getUser()
{
return $this->hasOne(User::className(), ['id' => 'user_favorited']);
}