cviebrock/eloquent-taggable

Hello i got an sql issue

atta1234 opened this issue · 3 comments

$deals = Deal::withAllTags($request->tag)->paginate('10');

dd($deals);

exit();
SQLSTATE[42000]: Syntax error or access violation: 1055 'lara8.deals.title' isn't in GROUP BY (SQL: select count(*) as aggregate from (select `deals`.* from `deals` inner join `taggable_taggables` as `taggable_taggables_scopewithalltags_1` on `deals`.`id` = `taggable_taggables_scopewithalltags_1`.`taggable_id` and `taggable_taggables_scopewithalltags_1`.`taggable_type` = App\Models\Deal where `taggable_taggables_scopewithalltags_1`.`tag_id` in (9) group by `deals`.`id` having COUNT(DISTINCT taggable_taggables_scopewithalltags_1.tag_id) = 1) as `aggregate_table`)

I suspect the SQL for handling the withAllTags method doesn't play nicely with Laravel's SQL for calculating pagination counts. Let me look into it.

The test I added above is pretty much a copy of your code, and it seems to work:

    public function testWithAllTagsPaginated(): void
    {
        /** @var \Illuminate\Pagination\LengthAwarePaginator $models */
        $models = TestModel::withAllTags('Apple,Banana')->paginate(2);

        $this->assertCount(2, $models->items());
        $this->assertEquals(3, $models->total());
    }

Your issue might be related to strict mode in MySQL. See #60 (comment) Can you confirm that setting in your database config?

Closing due to no response. Feel free to re-open or comment if you are still having issues.