clickbar / laravel-magellan

A modern PostGIS toolbox for Laravel
MIT License
193 stars 11 forks source link

stOrderBy #50

Closed boonstoppel closed 11 months ago

boonstoppel commented 1 year ago

when adding stOrderBy to a query it ignores the previous conditions on the query:

$places = Place::whereHas('user')
  ->stOrderBy(ST::distanceSphere(Point::makeGeodetic($lat, $lon), 'location'))
  ->get();

In the case above the condition whereHas is totally ignored.

ahawlitschek commented 1 year ago

Thanks for opening the issue. I will look into it

ahawlitschek commented 1 year ago

I just tried it with a similar call:

 Port::whereHas('ships')
        ->stOrderBy(ST::distanceSphere(Point::makeGeodetic(50.0, 8.0), 'location'))
        ->dd();

This resulted in the correct query:

SELECT
    *
FROM
    "ports"
WHERE
    EXISTS (
        SELECT
            *
        FROM
            "ships"
        WHERE
            "ports"."id" = "ships"."port_id")
    ORDER BY
        ST_DistanceSphere (public.ST_GeomFromEWKT ('SRID=4326;POINT(8 50)')::geometry,
            "location"::geometry) ASC;

Could you please perform your query with an ->dd() instead of the ->get() and paste the result?

studnitz commented 11 months ago

Closed due to no activity. If it's still a problem, we can reopen it anytime.