cviebrock / eloquent-taggable

Easily add the ability to tag your Eloquent models in Laravel.
MIT License
537 stars 72 forks source link

Hello i got an sql issue #115

Closed atta1234 closed 3 years ago

atta1234 commented 3 years ago
$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`)
cviebrock commented 3 years ago

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.

cviebrock commented 3 years ago

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 https://github.com/cviebrock/eloquent-taggable/issues/60#issuecomment-330493812 Can you confirm that setting in your database config?

cviebrock commented 3 years ago

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