使用 Geocoder 进行 Mongoid 查询
我一直在浏览 mongoid 文档、Geocoder 文档,并询问了一位朋友,但我仍然对此有些困惑。我有两个模型,Event 和 Place:
class Event
include Mongoid::Document
belongs_to :place
end
class Place
include Mongoid::Document
has_many :events
end
我已经设置了它们,以便 Event.place
和 Place.events
正常工作,但让我困惑的是将地理编码器附近方法合并到查询中。目前 Place.near(location)
工作正常,我想做的是按位置查询事件,所以 Event.place.near(location)
我已经尝试查看以下内容:
@events = Event.where('event.place' => close(location)
@events = Event.where(place.near(location))< /code>
任何帮助将不胜感激。
I've been going through the mongoid docs, Geocoder docs and have asked a friend, but am still a little stuck on this. I've got two Models, Event and Place:
class Event
include Mongoid::Document
belongs_to :place
end
class Place
include Mongoid::Document
has_many :events
end
I've set these up so that Event.place
and Place.events
work fine, the thing that is throwing me is incorporating the Geocoder near method into queries. Currently Place.near(location)
works fine, what I'm wanting to do is query Events by their location, so Event.place.near(location)
I've tried looking at things like:
@events = Event.where('event.place' => near(location)
@events = Event.where(place.near(location))
Any help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这不是吗
?您可以查询类似的事件
Wouldn't this to be
and you can query the events like
在处理 mongoDB 中的地理编码器和位置时,您可以受益的一个非常有用的宝石:
https://github.com/ ryanong/mongoid_spacial
A very useful gem you could benefit for when dealing with Geocoder and locations in general within mongoDB :
https://github.com/ryanong/mongoid_spacial