geokit / geokit-rails

Official Geokit plugin for Rails/ActiveRecord. Provides location-based goodness for your Rails app. Requires the Geokit gem.
MIT License
1.57k stars 245 forks source link

Make nearest and farthest return scopes, not arrays #68

Closed marcandre closed 9 years ago

marcandre commented 9 years ago

Simple PR to avoid returning an array when a scope will provide even more flexibility.

Note: the old geokit-rails3 was doing this too, so it's a compatibility issue also.

marcandre commented 9 years ago

Oups, fixed. I first tried using reverse_order but it fails on this order clause, so I modified slightly by_distance to accept a reverse option. Note that this fixes another issue with farthest, namely that last(1) was loading all matching records with to_a, so it could be really really slow. I hope to fix these two issues in Rails, but it involves a sql parser of some sort...