0

位置有 :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
4

1 回答 1

0

要将多态与 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)
于 2015-01-22T15:32:16.967 回答