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
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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.