0

Location has :lat and :lng for use with 'geokit-rails' I'm running Rails 4.

Is it possible to do a query for distinct Collections that have Tracks in a specified Location range?

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
scalhoun
  • 13
  • 3

1 Answers1

0

To use polymorphic with grokit-rails you have to add acts_as_mappable through: :location to your Tracks model:

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

And the query must be:

@collection.tracks.joins(:location).within(distance, :origin => @origin)
Moh
  • 249
  • 3
  • 15