我一直在瀏覽mongoid文檔,Geocoder文檔並詢問了一位朋友,但我仍然對此有所瞭解。我有兩個型號,事件和地點:使用地理編碼器的Mongoid查詢
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' => near(location)
@events = Event.where(place.near(location))
任何幫助將不勝感激。
使用這個頁面上的信息,http://stackoverflow.com/questions/4364213/mongoid-querying-by-referenced-document我已經想出了這個解決方案,但是如果可能的話,會喜歡看更優雅的東西: 'place_ids = Place.near(@ocation).map(&:_ id) @events = Event.where(:place_id.in => place_ids' – 2011-05-19 14:24:18