Find_by_sql not working

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())601.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?

I have an idea. If you call a
Model.connection.select_one("…")

before, do I need to call some kind of SQL close before moving on to the
next query?

On Aug 5, 1:46 am, Allen W. [email protected]
wrote:

I have an idea. If you call a
Model.connection.select_one(“…”)

before, do I need to call some kind of SQL close before moving on to the
next query?

Nope. Does it make any difference if you change select * to select
locations.* (on the off chance that you’ve got an attribute name there
which clashes with an activerecord/ruby function ?

Fred