eager loading associations fix belongs_to doesn't work

Aryk Grosz wrote:

I tried using the eager_custom_sql.rb fix to be able to eager load
associations using find_by_sql.

I was able to get this working for my has_many associations, however, Im
having trouble getting it to work for belongs_to associations.

Has anyone experienced this? Any fixes?

belongs_to doesn't support a :finder_sql option, so you can't
use fully-custom sql. I'd be interested to see a belongs_to
that actually requires it.

Aryk Grosz wrote:

Hmm, so if you want to use manual sql, how can you return a belongs_to object alongside the main object or do you just have to use the standard "find" with the "include" option?

Oh, you mean the belongs_to is the association you want eager loaded,
not that you want to use the :include method in the declaration
of a belongs_to, eager loading its descendants?

If so, find_by_sql and the :include option should work if you've
correctly written all the custom sql joins and field aliasing.