voten-co / voten

The code that powers voten.co
https://voten.co
Apache License 2.0
1.26k stars 233 forks source link

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

Open night1008 opened 6 years ago

night1008 commented 6 years ago

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')