Skip to content

[BUG] Pagination not working if query contain HAVING statement #3105

Closed
@Elyahou

Description

@Elyahou

I have a query that return the cities on a fixed distance from a point:

$query->addSelect(DB::Raw(
            '(3959 * acos (
              cos ( radians('.$lat.') )
              * cos( radians( lat ) )
              * cos( radians( lon ) - radians('.$lon.') )
              + sin ( radians('.$lat.') )
              * sin( radians( lat ) )
            )) AS distance'))
      ->having('distance', '<', 300)->paginate(10);

This cause this mysql error:

Column not found: 1054 Unknown column 'distance' in 'having clause'

Because the agregate query generated by the pagination class contain the having but not the select (distance)

select count(*) as aggregate from `cities` where `id` > 0 having `distance` < 300

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions