0

場所には、「geokit-rails」で使用するための :lat と :lng があります 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 でポリモーフィックを使用するには、acts_as_mappable through: :location を 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 に答える