diff --git a/lib/geocoder/stores/active_record.rb b/lib/geocoder/stores/active_record.rb index 9cf596dc82df1ce5eb41f349672aa3a5971dc4d8..9382aaa62338e1b40ae09f85e7c3c18c0fcb8b27 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