简体   繁体   English

Geokit-Rails:多态位置查询

[英]Geokit-Rails: polymorphic location query

Location has :lat and :lng for use with 'geokit-rails' I'm running Rails 4. 该位置具有:lat和:lng与“ geokit-rails”配合使用,我正在运行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: 要将多态与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

And the query must be: 查询必须是:

@collection.tracks.joins(:location).within(distance, :origin => @origin)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Geokit-rails新设置,找不到表“ locations” Rails 5 - Geokit-rails fresh setup, Could not find table 'locations' Rails 5 在模型实例方法中使用Geokit-Rails时出错 - Error while using Geokit-Rails in model instance method TypeError:没有使用geokit-rails搜索将Symbol隐式转换为Integer - TypeError: no implicit conversion of Symbol into Integer for search with geokit-rails geokit-rails的未定义方法&#39;merge_conditions&#39; - undefined method 'merge_conditions' for geokit-rails RoR:如何使用geokit-rails获取经纬度 - RoR: How to get lat and lng using geokit-rails 未定义的方法&#39;distance_betwwen&#39;geokit-rails - undefined method `distance_betwwen' geokit-rails ArgumentError: Unknown key: origin using geokit-rails - ArgumentError: Unknown key: origin using geokit-rails 使用Geokit-Rails按起点和终点位置搜索信息 - Searching Post by Origin & Destination locations using Geokit-Rails Geokit-rails插件-无法在返回的GeoLoc对象上调用to_json,给出循环引用错误 - Geokit-rails plugin - can't call to_json on returned GeoLoc object, gives circular reference error 使用Geokit-Rails,如何找到距离内的所有字段,或者将位值设置为1 - Using Geokit-Rails, How can I find all fields within a distance OR have a bit value set to 1
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM