Ruby on Rails
Eager Finder SQL Plugin

This plugin adds custom SQL to be used when eager loading assoiations through find..

Usage:
Install plugin:
script/plugin install svn://rubyforge.org/var/svn/eagerfindersq

Then to find instances of your model, just do:

Model.find(:all, :include => :association, :finder_sql => QUERY, :column_mapping => MAPPING)

Please visit this project’s home page for a complete information:

I found this useful tip
while searching for a way to solve a frustrating incorrect id problem in finder_sql option