【发布时间】:2012-04-13 10:35:21
【问题描述】:
就我而言,我有一个模型产品 has_one Location
我使用地理编码器 gem 来搜索附近的位置。
请求 Location.near([0, 0], 100) 如下所示:
选择位置。*, 6371.0 * 2 * ASIN(SQRT(POWER(SIN((0 - locations.latitude) * PI() / 180 / 2), 2) + COS(0 * PI() / 180) * COS(locations.latitude * PI() / 180) * POWER(SIN((1 - locations.longitude) * PI() / 180 / 2), 2) )) 作为距离,CAST(DEGREES(ATAN2( RADIANS(经度 - 1), RADIANS(latitude - 0))) + 360 AS 十进制) % 360 AS 方位来自\"locations\" WHERE (6371.0 * 2 * ASIN(SQRT(POWER(SIN((0 - locations.latitude) * PI() / 180 / 2), 2) + COS(0 * PI() / 180) * COS(locations.latitude * PI() / 180) * POWER(SIN((1 - locations.longitude) * PI( ) / 180 / 2), 2) ))
我想做这样的事情:
Product.where(...).joins(:location).dosomething
我该怎么做?
【问题讨论】:
标签: ruby-on-rails activerecord arel