class Company < ApplicationRecord
has_many :addresses
acts_as_geolocated through: :addresses
end
class Address < ApplicationRecord
acts_as_geolocated lat: 'latitude', lng: 'longitude'
belongs_to :company
end
> Company.within_radius(20_000, *point).selecting_distance_from(*point).first.distance
=> 11081.8179360831
> Company.includes(:addresses).within_radius(20_000, *point).selecting_distance_from(*point).first.distance
NoMethodError: undefined method `distance' for #<Company:0x00007fbbd7584888>
Separately, just wonder if it's possible to query Company but have the distance method attached to the the addresses?
Separately, just wonder if it's possible to query Company but have the distance method attached to the the addresses?