I have the following complex query:

locations = Location.find_by_sql(“SELECT * FROM locations join

mediaGeography on locations.zip = mediaGeography.geoZip WHERE

(((acos(sin(( #{coords[“geoLAT”]} * pi()/180)) * sin((

mediaGeography.geoLAT * pi()/180)) + cos(( #{coords[“geoLAT”]} *

pi()/180)) * cos((mediaGeography.geoLAT * pi()/180)) *

cos(((#{coords[“geoLON”]} -mediaGeography.geoLON ) *

pi()/180))))*180/pi())*60*1.1515) < #{ distance }”)

Obviously messy. I *DO NOT* have a “mediaGeography” model but there is a

table in my DB called “mediaGeography”. Anyway this returns 0

“locations” when it should return 15. If I go to ‘development.log’ file

and copy and paste the generated query there directly to mysql it does

return the right number of columns, i.e. 15 and not 0.

Any ideas?