in the script I am using, I checked the statement :
f = find_with_associations(options.merge(:sql => sanitized_sql))
That looks like my eager_custom_sql.rb mod.
where
sql = "SELECT..." my select, running fine in sql client mode or
find_by_sql()
and
options.inspect
=> "{:include=>[:user, :city, {:category=>:domain}]}"
this find_with_associations() just bring me back an empty record
SELECT *, (6366*acos(cos(0.853291)*cos(cities.latitude) * cos(cities.longitude - (0.040841))+sin(0.853291)*sin(cities.latitude))) as km FROM proposals INNER JOIN users ON proposals.user_id = users.id INNER JOIN cities ON proposals.city_id = villes.id INNER JOIN categories ON proposals.category_id = categories.id INNER JOIN domains ON categories.domain_id = domains.id WHERE proposals.city_id IN (31556,37294,31547,37302,31548,31555,31546,31557,37236,31540,31541) AND (6366*acos(cos(0.853291)*cos(cities.latitude) * cos(cities.longitude-(0.040841))+sin(0.853291)*sin(cities.latitude))) < 25.0 AND (valid_until >= '2007-01-21 09:25:15' OR valid_until IS NULL) ORDER BY km LIMIT 0,4
so, it's a select all, only a calculated value as km..
If you use the :include option you have to specially alias all your
selected fields in the way described in the comment at the top of
the mod, plus use left joins. And I'm not sure if it's possible to
also select some calculated fields.
Do you really need the returned proposal models to have the included
associated models chained off them, or do you just need to join the
other tables for use in the calculations and conditions?
In this case I just need to join the other tables for use in the calculations and conditions,
the resulting list is the proposals list... from there ones can link_to the proposal.user only
(:cities , :category and :domain models are used only for conditions and calculations...)
Don't use the :include option then. Either use find_by_sql, or use a
normal find with specified :select, :joins, :conditions, and :order
options.