lundi 6 mai 2019

Laravel Eloquent GroupBy throwing SQL error

When I run the below SQL manually I get my expected results with no error

select * from `crawl_results` 
    where `user_id` = 1 and `website_id` = 1 
    and `item_state` != 'OK' group by `destination_url` 
    limit 30 offset 0

However when I run this in Eloquent...

self::where('user_id', Auth::id())
    ->where('website_id', $scanID)
    ->where('item_state', '!=' , 'OK')
    ->groupby('destination_url')->paginate(30)

It produces this error:

SQLSTATE[42000]: Syntax error or access violation: 1055 'link_checker.crawl_results.id' isn't in GROUP BY (SQL: select * from crawl_results where user_id = 1 and website_id = 1 and item_state != OK group by destination_url limit 30 offset 0)

Not sure what is happening behind the abstraction to produce that error?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire