Module: ActiveRecordPostgresEarthdistance::QueryMethods

Defined in:
lib/activerecord-postgres-earthdistance/acts_as_geolocated.rb

Instance Method Summary collapse

Instance Method Details

#selecting_distance_from(lat, lng, name = "distance", include_default_columns = true) ⇒ Object



50
51
52
53
54
55
56
57
# File 'lib/activerecord-postgres-earthdistance/acts_as_geolocated.rb', line 50

def selecting_distance_from lat, lng, name="distance", include_default_columns=true
  clone.tap do |relation|
    values = []
    values << relation.arel_table[Arel.star] if relation.select_values.empty? && include_default_columns
    values << "earth_distance(ll_to_earth(#{self.latitude_column}, #{self.longitude_column}), ll_to_earth(#{lat}, #{lng})) as #{name}"
    relation.select_values = values
  end
end