From 8ee2b83a6d37dd806c0b7e11359f99b31c7d5710 Mon Sep 17 00:00:00 2001 From: Joe Terry Date: Thu, 30 Mar 2023 13:58:15 -0400 Subject: [PATCH] only join with through_table if it exists --- lib/activerecord-postgres-earthdistance/acts_as_geolocated.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/activerecord-postgres-earthdistance/acts_as_geolocated.rb b/lib/activerecord-postgres-earthdistance/acts_as_geolocated.rb index ebfd2c4..fd1dac9 100644 --- a/lib/activerecord-postgres-earthdistance/acts_as_geolocated.rb +++ b/lib/activerecord-postgres-earthdistance/acts_as_geolocated.rb @@ -2,7 +2,6 @@ module ActiveRecordPostgresEarthdistance MILES_TO_METERS_FACTOR = 1609.344 module ActsAsGeolocated extend ActiveSupport::Concern - module ClassMethods def acts_as_geolocated(options = {}) @@ -95,7 +94,7 @@ def self.quote_value(value) module QueryMethods def selecting_distance_from(lat, lng, name = "distance", include_default_columns = true) clone.tap do |relation| - relation.joins!(through_table) + relation.joins!(through_table) if through_table values = [] if relation.select_values.empty? && include_default_columns values << relation.arel_table[Arel.star]