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

Add :select option to approx_near_scope_options.

This option is not recommended but it must be available for consistency.
The API should support the same options regardless of the algorithm used
for finding nearby objects.

Also move shared :conditions to default_near_scope_options.
parent 60df0428
No related branches found
No related tags found
No related merge requests found
......@@ -84,9 +84,6 @@ module Geocoder
"PI() / 180 / 2), 2) ))"
default_near_scope_options(latitude, longitude, radius, options).merge(
:select => "#{options[:select] || '*'}, #{distance} AS distance",
:conditions => \
["#{lat_attr} BETWEEN ? AND ? AND #{lon_attr} BETWEEN ? AND ?"] +
coordinate_bounds(latitude, longitude, radius),
:having => "#{distance} <= #{radius}"
)
end
......@@ -98,12 +95,8 @@ module Geocoder
# objects outside the given radius).
#
def approx_near_scope_options(latitude, longitude, radius, options)
lat_attr = geocoder_options[:latitude]
lon_attr = geocoder_options[:longitude]
default_near_scope_options(latitude, longitude, radius, options).merge(
:conditions => \
["#{lat_attr} BETWEEN ? AND ? AND #{lon_attr} BETWEEN ? AND ?"] +
coordinate_bounds(latitude, longitude, radius)
:select => options[:select] || nil
)
end
......@@ -111,10 +104,15 @@ module Geocoder
# Options used for any near-like scope.
#
def default_near_scope_options(latitude, longitude, radius, options)
lat_attr = geocoder_options[:latitude]
lon_attr = geocoder_options[:longitude]
{
:order => options[:order],
:limit => options[:limit],
:offset => options[:offset]
:offset => options[:offset],
:conditions => \
["#{lat_attr} BETWEEN ? AND ? AND #{lon_attr} BETWEEN ? AND ?"] +
coordinate_bounds(latitude, longitude, radius)
}
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