Geokit-Rails:多态位置查询



Location has:lat and:lng for use with 'geokit-rails' .

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

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)

相关内容

  • 没有找到相关文章

最新更新