Eager Finder SQL 12

Posted by gkellogg Mon, 06 Nov 2006 11:31:00 GMT

EagerFinderSql allows custom SQL to be specified when doing eager loading of associations through the :include option
to find. This allows for purpose-constructed queries to be used and still result in a fully linked
object model.

Background

ActiveRecord constructs SQL to satisfy the requirements of a find request. Associations allow for customized
SQL to be specified, using the :finder_sql option, but this has not been available when performing eager loading
using the :include option. The result is that a standardized query is constructed to bring in the associated
tables using LEFT OUTER JOIN. For some queries, this can be result in expensive queries and potentially very
large result sets.

Custom SQL

EagerFinderSql addresses this problem by allowing :finder_sql to be added
to find options when the :include option is also specified.