class User < AR
has_many :locations
end
class Location < AR
belongs_to :user
geocoded_by :address
end
我如何写一个查询做到这一点?
@users = User._a_query_that_returns_users_in_'Paris'_
可能有一种更优雅的方法,但是您可以与Location表连接并使用地理编码器near
方法来执行查询。像这样:
near = Location.near('Paris, France')
@users = User.joins(:locations).merge(near)