class User < AR
has_many :locations
end
class Location < AR
belongs_to :user
geocoded_by :address
end
How do I write a query that does this?
@users = User._a_query_that_returns_users_in_'Paris'_
class User < AR
has_many :locations
end
class Location < AR
belongs_to :user
geocoded_by :address
end
How do I write a query that does this?
@users = User._a_query_that_returns_users_in_'Paris'_
There might be a more elegant approach, but you can join with the Location table and use the geocoder near
method to do the query. Something like this:
near = Location.near('Paris, France')
@users = User.joins(:locations).merge(near)
© 2022 - 2024 — McMap. All rights reserved.
Profile.joins(:address).merge(Address.near('Dallas, TX')).first.attributes.keys
Profile Load (3.8ms) => ["id", "location", "latitude", "longitude", "city", "state", "state_code", "postal_code", "country", "country_code", "created_at", "updated_at", "distance", "bearing"]
– Sensitometer