3

我在我的应用程序中使用 GeoCoder。现在我需要在我的数据库中搜索靠近某个位置或具有特定属性集的对象。我想在一个数据库查询中执行此操作,因为数据库真的很大。

我想要类似的东西

  Spot.near([lat,long],distance).where("visited = ?",true). 

距离和访问属性应与 OR 组合,而不是与 AND。

有谁知道如何做到这一点?

谢谢!

4

1 回答 1

4

根据这个答案,您应该能够执行以下操作:

near = Spot.near([lat, long], distance)
visited = Spot.where(visited: true)

near = near.where_values.reduce(:and)
visited = visited.where_values.reduce(:and)

Spot.where(near.or(visited))
于 2013-02-24T22:08:36.593 回答