# Eager Finder SQL

**URL:** <https://www.ruby-forum.com/t/eager-finder-sql/75054>\
**Category:** Rails\
**Created:** [November 7, 2006, 11:08am UTC](https://www.ruby-forum.com/t/eager-finder-sql/75054 "2006-11-07T11:08:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gkellogg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/73ab20/32.png) [@gkellogg](https://www.ruby-forum.com/u/gkellogg)\
**Post date:** [November 7, 2006, 11:08am UTC](https://www.ruby-forum.com/t/eager-finder-sql/75054/1 "2006-11-07T11:08:14Z")

</div>

Hi, I just uploaded a Rails plugin that allows you to specify custom  
SQL when doing a find with associations (AKA eager loading).

One of the problems I encountered when implementing the Chacha  
Underground ([http://underground.chacha.com](http://underground.chacha.com)) was being able to use  
queries provided by the DBA to efficiently get all the informaion I  
needed to render a page. In some cases, I needed to go two or three  
associations deep in a model and the SQL generated by ActiveRecord was  
either inadequate or lead to huge result sets. My solution was to  
create a mixin that allowed my to specify a :finder\_sql option to the  
find method. In conjunction with the :column\_mapping option, I could  
then have full control of the queries generated and reduce the number  
and overhead of the queries needed to render a page.

Please check out my blog entry on it for a fuller description:  
[http://kellogg-assoc.com/articles/2006/11/05/eager-finder-sql](http://kellogg-assoc.com/articles/2006/11/05/eager-finder-sql).

Gregg Kellogg

---

<div class="post-metadata">

**Author:** ![gkellogg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/73ab20/32.png) [@gkellogg](https://www.ruby-forum.com/u/gkellogg)\
**Post date:** [November 7, 2006, 1:18pm UTC](https://www.ruby-forum.com/t/eager-finder-sql/75054/2 "2006-11-07T13:18:44Z")

</div>

That looks pretty awesome - I’ve felt the need for something like this  
several times in the past.

Thanks!

Fred

---

<div class="post-metadata">

**Author:** ![gkellogg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/73ab20/32.png) [@gkellogg](https://www.ruby-forum.com/u/gkellogg)\
**Post date:** [November 7, 2006, 3:30pm UTC](https://www.ruby-forum.com/t/eager-finder-sql/75054/3 "2006-11-07T15:30:05Z")

</div>

Hi

> Please check out my blog entry on it for a fuller description:  
> [http://kellogg-assoc.com/articles/2006/11/05/eager-finder-sql](http://kellogg-assoc.com/articles/2006/11/05/eager-finder-sql).

Wow. Fantastic. I have had to write some very complicated custom SQL  
queries for a project and this looks like a great way for me to get the  
results back into the OO model!

If this works the way it appears to then it should definitely become  
part of core Rails…!

Ed W
