在Laravel 5.2中使用的查询给我Laravel 5.3中的错误 [英] query that worked in Laravel 5.2 give me error in Laravel 5.3
本文介绍了在Laravel 5.2中使用的查询给我Laravel 5.3中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
此查询在5.2中工作:
This query works in 5.2:
$galleries = Gallery::with(array(
'images' => function ($query) {
$query->orderBy('order', 'asc');
}
))
->with('votes')
->leftJoin('votes', 'votes.votable_id', '=', 'gallery.id')
->selectRaw(
'gallery.*, count(case votes.status when "upvote" then 1 else null end) - count(case votes.status when "downvote" then 1 else null end) as points'
)
->where('votes.votable_type','App\Gallery')
->groupBy('gallery.id')
->orderBy('points', 'desc')
->published()->orderBy('gallery.created_at', 'desc')->paginate(30);
我试图选择所有有投票的画廊,当我在5.3中运行这个, / p>
I am trying to select all galleries that have votes, when I run this in 5.3 I get this
1/2 PDOException in Connection.php line 333: SQLSTATE[42000]:
Syntax error or access violation: 1055 'images.gallery.title' isn't in GROUP BY
SQLSTATE[42000]: Syntax error or access violation: 1055 'images.gallery.title' isn't in
GROUP BY (SQL: select gallery.*, count(case votes.status when "upvote" then 1 else null end) - count(case votes.status when "downvote" then 1 else null end)
as points from `gallery` left join `votes` on `votes`.`votable_id` = `gallery`.`id`
where `votes`.`votable_type` = App\Gallery and `published` = 1 group by `gallery`.`id`
order by `points` desc, `gallery`.`created_at` desc limit 30 offset 0)
推荐答案
转到你的config / database.php文件夹。在mysql配置数组中,更改 strict => true
to strict =>
,一切都会很好的工作。
Go to your config/database.php folder. In mysql configuration array, change strict => true
to strict => false
, and everything will work nicely.
这篇关于在Laravel 5.2中使用的查询给我Laravel 5.3中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文