Skip to content
Snippets Groups Projects
Commit f1bdbd8c authored by Alex Reisner's avatar Alex Reisner
Browse files

Merge pull request #416 from dimko/patch-1

Fix deprecation warnings on active record scopes
parents a263ec98 da999dcd
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment