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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With