geokit / geokit-rails

Official Geokit plugin for Rails/ActiveRecord. Provides location-based goodness for your Rails app. Requires the Geokit gem.
MIT License
1.57k stars 245 forks source link

AAM::add_distance_to_select: uses "*" for SQL SELECT clause, better would be "table_name.*" #17

Closed jensb closed 3 years ago

jensb commented 14 years ago
diff --git a/vendor/plugins/geokit-rails/lib/geokit-rails/acts_as_mappable.rb b/vendor/plugins/geokit-rails/lib/g
index b64af74..339ccfa 100644
--- a/vendor/plugins/geokit-rails/lib/geokit-rails/acts_as_mappable.rb
+++ b/vendor/plugins/geokit-rails/lib/geokit-rails/acts_as_mappable.rb
@@ -388,7 +388,7 @@ module Geokit
         def add_distance_to_select(options, origin, units=default_units, formula=default_formula)
           if origin
             distance_selector = distance_sql(origin, units, formula) + " AS #{distance_column_name}"
-            selector = options.has_key?(:select) && options[:select] ? options[:select] : "*"
+            selector = options.has_key?(:select) && options[:select] ? options[:select] : "#{self.table_name}.*"
             options[:select] = "#{selector}, #{distance_selector}"  
           end
         end
jensb commented 14 years ago

This has bitten me when I used a "default_scope" in my mappable model which contained JOIN clauses. This would cause PostgreSQL to select rows from JOINed tables in addition to the rows from the mappable model's table. Thank god for tests!

myronmarston commented 14 years ago

I found this issue, as well. I reported it here.

ryankopf commented 3 years ago

I am closing all issues that are more than 6 years old now, as the gem has had significant updates and is likely people with these old issues are no longer having the issues. If you are currently still experiencing this issue or need help feel free to submit a new issue, thank you.