亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

從 Laravel 范圍查詢中排除連接列 ONLY_FULL_GROUP_BY 錯誤

從 Laravel 范圍查詢中排除連接列 ONLY_FULL_GROUP_BY 錯誤

PHP
烙印99 2021-10-15 16:41:48
我在 Laravel 項目中有一個范圍查詢,它隱式地獲取了結果集中我不想要的兩列,因為它們導致 ONLY_FULL_GROUP_BY 錯誤,我不想禁用此數據庫條件。我們有以下關系:組織有 -> 類別public function categories(){    return $this->belongsToMany(        Category::class,        'organisation_unit_template_categories',        'organisation_unit_id',        'template_category_id'    );}類別有 -> 模板public function templates(){    return $this->hasMany(Template::class);}模板有 -> 尺寸public function dimensions(){    return $this->belongsTo(Dimensions::class, 'dimensions_id');}我們的類別也有一個范圍查詢,這樣我們就可以得到所有包含至少一個維度為 'digital = 0' 的模板的類別public function scopeIsPrint($query){    return $query        ->select($this->getTable().'.*')        ->join('templates', 'template_categories.id', '=', 'templates.category_id')        ->join('template_dimensions', 'template_dimensions.id', '=', 'templates.dimensions_id')        ->where('template_dimensions.digital', 0)        ->groupBy($this->getTable().'.id');}我們從控制器調用范圍查詢,如下所示:$categories = $this->organisation->categories()->isPrint()->get();這是輸出:SELECT     `template_categories`.*,    `organisation_unit_template_categories`.`organisation_unit_id` AS `pivot_organisation_unit_id`,    `organisation_unit_template_categories`.`template_category_id` AS `pivot_template_category_id`FROM    `template_categories`        INNER JOIN    `organisation_unit_template_categories` ON `template_categories`.`id` = `organisation_unit_template_categories`.`template_category_id`        INNER JOIN    `templates` ON `template_categories`.`id` = `templates`.`category_id`        INNER JOIN    `template_dimensions` ON `template_dimensions`.`id` = `templates`.`dimensions_id`WHERE    `organisation_unit_template_categories`.`organisation_unit_id` = 2        AND `template_dimensions`.`digital` = 0        AND `template_categories`.`deleted_at` IS NULLGROUP BY `template_categories`.`id`
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 198 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號