Rewrite query using heredoc syntax for greater readability
This commit is contained in:
parent
51651ddcf5
commit
511d44875e
|
@ -2,7 +2,13 @@ class Hydrant < ActiveRecord::Base
|
|||
belongs_to :user
|
||||
|
||||
def self.find_closest(lat, lng, limit=50)
|
||||
Hydrant.find_by_sql(["SELECT *, (3959 * ACOS(COS(RADIANS(?)) * COS(RADIANS(lat)) * COS(radians(lng) - RADIANS(?)) + SIN(RADIANS(?)) * SIN(RADIANS(lat)))) AS distance FROM hydrants ORDER BY distance LIMIT ?", lat, lng, lat, limit])
|
||||
query = <<-SQL
|
||||
SELECT *, (3959 * ACOS(COS(RADIANS(?)) * COS(RADIANS(lat)) * COS(radians(lng) - RADIANS(?)) + SIN(RADIANS(?)) * SIN(RADIANS(lat)))) AS distance
|
||||
FROM hydrants
|
||||
ORDER BY distance
|
||||
LIMIT ?
|
||||
SQL
|
||||
Hydrant.find_by_sql([query, lat, lng, lat, limit])
|
||||
end
|
||||
|
||||
def adopted?
|
||||
|
|
Loading…
Reference in New Issue