繁体   English   中英

Geokit-Rails:多态位置查询

[英]Geokit-Rails: polymorphic location query

该位置具有:lat和:lng与“ geokit-rails”配合使用,我正在运行Rails 4。

是否可以查询在指定位置范围内具有轨道的不同集合?

class Location < ActiveRecord::Base
  belongs_to :locatable, polymorphic: true
  acts_as_mappable
end

class Tracks < ActiveRecord::Base
has_one :location, as: :locatable
belongs_to :collection
end

class Collection < ActiveRecord::Base
  belongs_to :user
  has_many :tracks
end

要将多态与grokit-rails一起使用,您必须通过::location将acts_as_mappable添加到Tracks模型中:

class Tracks < ActiveRecord::Base
  has_one :location, as: :locatable
  acts_as_mappable through: :location
  belongs_to :collection
end

查询必须是:

@collection.tracks.joins(:location).within(distance, :origin => @origin)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM