Skip to content

Commit

Permalink
Include table name in select clause.
Browse files Browse the repository at this point in the history
This avoids selecting all fields from all joined tables, which confuses
ActiveRecord (assigns returned object the wrong ID).
  • Loading branch information
alexreisner committed Nov 22, 2011
1 parent 38db9d1 commit 47edf4e
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/geocoder/stores/active_record.rb
Expand Up @@ -135,7 +135,7 @@ def full_near_scope_options(latitude, longitude, radius, options)
"POWER(SIN((#{longitude} - #{lon_attr}) * PI() / 180 / 2), 2) ))"
options[:order] ||= "#{distance} ASC"
default_near_scope_options(latitude, longitude, radius, options).merge(
:select => "#{options[:select] || '*'}, " +
:select => "#{options[:select] || "#{table_name}.*"}, " +
"#{distance} AS distance" +
(bearing ? ", #{bearing} AS bearing" : ""),
:having => "#{distance} <= #{radius}"
Expand Down Expand Up @@ -175,7 +175,7 @@ def approx_near_scope_options(latitude, longitude, radius, options)
distance = "(#{dy} * ABS(#{lat_attr} - #{latitude}) * #{factor}) + " +
"(#{dx} * ABS(#{lon_attr} - #{longitude}) * #{factor})"
default_near_scope_options(latitude, longitude, radius, options).merge(
:select => "#{options[:select] || '*'}, " +
:select => "#{options[:select] || "#{table_name}.*"}, " +
"#{distance} AS distance" +
(bearing ? ", #{bearing} AS bearing" : ""),
:order => distance
Expand Down

0 comments on commit 47edf4e

Please sign in to comment.