为什么这对我的laravel代码来说是一个错误?

时间:2018-06-12 14:43:34

标签: php laravel-5.5

我在laravel中有这段代码

    $blogs = BlogCategoryGroup::with([
      'blogPost' => function($query) {
        $query
          ->with([
            'groups' => function($query) {
              $query->with('blogTag')->get();
            }])
          ->get();
      },
      'blogCategory'
    ])
    ->groupBy('blog_category_groups.blog_post_id')
    ->whereCategoryId($request->input('parent_category'))
    ->orWhere('category_id', $request->input('first_sub_category'))
    ->orWhere('category_id', $request->input('second_sub_category'))
    ->get();

具有等效查询

select * from `blog_category_groups` where `category_id` = 2 or `category_id` = 3 or `category_id` = 4 group by `blog_category_groups`.`blog_post_id`

运行laravel代码时的差异,我得到了这个错误

SQLSTATE[42000]: Syntax error or access violation: 1055 'database.blog_category_groups.id' isn't in GROUP BY (SQL: select * from `blog_category_groups` where `category_id` = 2 or `category_id` = 3 or `category_id` = 4 group by `blog_category_groups`.`blog_post_id`)

但是在heidiSQL上运行查询我得到了一个结果

为什么这对我的laravel代码来说是一个错误?

0 个答案:

没有答案