From da999dcd0ca4a4975fdcc3234a5b864d5638704e Mon Sep 17 00:00:00 2001
From: Dimko <deemox@gmail.com>
Date: Tue, 12 Mar 2013 04:59:30 +0400
Subject: [PATCH] Update active record scopes to return actual scope object
instead of hash
---
lib/geocoder/stores/active_record.rb | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/lib/geocoder/stores/active_record.rb b/lib/geocoder/stores/active_record.rb
index 9cf596dc..9382aaa6 100644
--- a/lib/geocoder/stores/active_record.rb
+++ b/lib/geocoder/stores/active_record.rb
@@ -18,13 +18,15 @@ module Geocoder::Store
# scope: geocoded objects
scope :geocoded, lambda {
- {:conditions => "#{geocoder_options[:latitude]} IS NOT NULL " +
- "AND #{geocoder_options[:longitude]} IS NOT NULL"}}
+ where("#{geocoder_options[:latitude]} IS NOT NULL " +
+ "AND #{geocoder_options[:longitude]} IS NOT NULL")
+ }
# scope: not-geocoded objects
scope :not_geocoded, lambda {
- {:conditions => "#{geocoder_options[:latitude]} IS NULL " +
- "OR #{geocoder_options[:longitude]} IS NULL"}}
+ where("#{geocoder_options[:latitude]} IS NULL " +
+ "OR #{geocoder_options[:longitude]} IS NULL")
+ }
##
# Find all objects within a radius of the given location.
@@ -36,7 +38,9 @@ module Geocoder::Store
scope :near, lambda{ |location, *args|
latitude, longitude = Geocoder::Calculations.extract_coordinates(location)
if Geocoder::Calculations.coordinates_present?(latitude, longitude)
- near_scope_options(latitude, longitude, *args)
+ options = near_scope_options(latitude, longitude, *args)
+ select(options[:select]).where(options[:conditions]).
+ order(options[:order])
else
# If no lat/lon given we don't want any results, but we still
# need distance and bearing columns so you can add, for example:
@@ -54,11 +58,11 @@ module Geocoder::Store
scope :within_bounding_box, lambda{ |bounds|
sw_lat, sw_lng, ne_lat, ne_lng = bounds.flatten if bounds
if sw_lat && sw_lng && ne_lat && ne_lng
- {:conditions => Geocoder::Sql.within_bounding_box(
+ where(Geocoder::Sql.within_bounding_box(
sw_lat, sw_lng, ne_lat, ne_lng,
full_column_name(geocoder_options[:latitude]),
full_column_name(geocoder_options[:longitude])
- )}
+ ))
else
select(select_clause(nil, "NULL", "NULL")).where(false_condition)
end
--
GitLab