voten icon indicating copy to clipboard operation
voten copied to clipboard

voten/app/Traits/CachableChannel.php has group by error

Open night1008 opened this issue 6 years ago • 0 comments

Illuminate/Database/QueryException with message 'SQLSTATE[42803]: Grouping error: 7 ERROR: column "suggesteds.id" must appear in the GROUP BY clause or be used in an aggregate function LINE 1: select "id", "channel_id" from "suggesteds" group by "channe... ^ (SQL: select "id", "channel_id" from "suggesteds" group by "channel_id")'

id caused from

public function getDefaultChannels()
 {
     return Cache::remember('default-channels-ids', 60 * 60 * 24, function () {
         return \App\Suggested::groupBy('channel_id')->select('id', 'channel_id')->pluck('channel_id');
     });
}

it should be

 \App\Suggested::groupBy('channel_id')->select('channel_id')->pluck('channel_id')

or

 \App\Suggested::distinct('channel_id')->select('channel_id')->pluck('channel_id')

night1008 avatar Jul 05 '18 13:07 night1008