yii2 hasone报错的解决办法:首先根据documentation打开相应的文件;然后修改语句为“function getUser(){return $this->hasOne(User::className...)}”即可。

yii2 hasOne关系工作错误
具体问题:
我有2个表:用户和收藏者:
users table favorite
现在,我在“收藏夹”模型中建立了如下所示的关系
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))",
请帮我!
推荐:《yii教程》
解决方法:
根据documentation,您必须使用:
public function getUser()
{
return $this->hasOne(User::className(), ['id' => 'user_favorited']);
}以上就是yii2 hasone 报错怎么办的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号