laravel-enso/tables

Count not working if you use join and group by

Closed this issue · 4 comments

This is a bug.

Prerequisites

  • Are you running the latest version?
  • Are you reporting to the correct repository?
  • Did you check the documentation?
  • Did you perform a cursory search?

Description

Please see ticket #152. I created this ticket because no resolution was made to #152.

See #152 latest comment:

Hi there,

We had the same issue with the count:

Table::selectRaw('
    table1.id,
    table1.name as TableName,
    GROUP_CONCAT(DISTINCT table2.name) as "table2Name",
    table1.type,
	table2.name
')
    ->leftJoin('.....')
    ->groupBy(
        'table1.name'
    ) 

And according to
laravel/ideas#1693
laravel/framework#22883
and what @aocneanu said, it is indeed a "problem" with how Laravel query builder works.

We went for this work-around:

laravel-enso\tables\src\app\Services\Data\Builders\Meta.php

Replace:

return $this->query->count(); 

With:

return $this->query->getQuery()->getCountForPagination(); 

and by "replace" I mean by binding local class that overwrites only the count() method from Meta.

I hope you can include this fix in future updates, Thanks!

I'll look into it

Many thanks!

@adithewonderboy tested, great catch!