我試圖做的是這裏所描述geosearching: http://freelancing-god.github.com/ts/en/geosearching.html思考獅身人面像 - 與HAS_ONE態關聯
除,而不是我的模型具有緯度和經度列,我想做的事:
class Post
has_one :location, :as => :locationable
end
class User
has_one :location, :as => :locationable
end
class Location
belongs_to :locationable, :polymorphic => true
end
使用戶和帖子都可以有位置記錄由locationable_type設置和locationable_id ......所以,我沒有在我的崗位模型如下:
define_index do
has locationable(:id), :as => :locationable_id
has "RADIANS(locations.lat)", :as => :latitude, :type => :float
has "RADIANS(locations.lng)", :as => :longitude, :type => :float
end
但我在'字段列表'錯誤中收到未知列...
我在做什麼錯?
是的,我原本試過 - 再試一次,那也行不通。我是可疑的,它會工作,因爲從閱讀獅身人面像文檔,似乎當你做這樣的事情:「RADIANS(locationable.lat)」它會直接對話數據庫(沒有ruby/rails),並沒有這樣只要數據庫知道這個東西就可以定位 - 這是一個不可思議的軌道事物。實際的表名是「位置」,所以似乎獅身人面像需要引用它,不是嗎? – patrick 2012-01-08 18:39:40
由於多態關係,您可能需要添加一些數據。 – mustafaturan 2012-01-08 21:32:20