96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
# File 'lib/activerecord-postgres-earthdistance/acts_as_geolocated.rb', line 96
def selecting_distance_from(lat, lng, name = "distance", include_default_columns = true)
clone.tap do |relation|
relation.joins!(through_table)
values = []
if relation.select_values.empty? && include_default_columns
values << relation.arel_table[Arel.star]
end
distances = Utils.earth_distance(through_table_klass, lat, lng, name)
distances = Arel::Nodes::Multiplication.new(
Utils.quote_value(1 / MILES_TO_METERS_FACTOR), distances
) if relation.distance_unit === :miles
values << distances
relation.select_values = values
end
end
|