# :select and :include in find are incompatible

**URL:** <https://discuss.rubyonrails.org/t/select-and-include-in-find-are-incompatible/16120>\
**Category:** rubyonrails-talk\
**Created:** [July 24, 2007, 11:23pm UTC](https://discuss.rubyonrails.org/t/select-and-include-in-find-are-incompatible/16120 "2007-07-24T23:23:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bphogan](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/bphogan/32/4186_2.png) [@bphogan](https://discuss.rubyonrails.org/u/bphogan)\
**Post date:** [July 24, 2007, 11:23pm UTC](https://discuss.rubyonrails.org/t/select-and-include-in-find-are-incompatible/16120/1 "2007-07-24T23:23:10Z")

</div>

Sure… don’t eager load. Get your first result set… then use collect to grab the ids.

ids\_to\_find = @results.collect{|r| [r.id](http://r.id)}

Then you can use that array in another finder.

either like this:

more\_results = Result.find(ids\_to\_find)

or

more\_results = Result.find(:all, include =\>[:other\_stuff], :conditions=\>[“[results.id](http://results.id) in (?)”, ids\_to\_find]

Would that work?

---

<div class="post-metadata">

**Author:** ![Matt\_Kull](https://avatars.discourse-cdn.com/v4/letter/m/65b543/32.png) [@Matt\_Kull](https://discuss.rubyonrails.org/u/Matt_Kull)\
**Post date:** [August 6, 2007, 8:54pm UTC](https://discuss.rubyonrails.org/t/select-and-include-in-find-are-incompatible/16120/2 "2007-08-06T20:54:27Z")

</div>

I have created a plugin (my first) which monkey patches the functionality submitted in [http://dev.rubyonrails.org/ticket/7147](http://dev.rubyonrails.org/ticket/7147) into ActiveRecord, with several modifications.

It has been modified to use a new naming convention for :include relationships.

Instead of using t[table\_index]\_r[column\_index] I am now using a more human readable convention of the form table\_name[index]\_\_column\_name.

Also, One of our requirements was the ability to extract an ActiveRecord object hierarchy from an arbitrary (albeit following the naming convention) result set. This is now possible through the extract\_objects(rows) method. We had several find methods which had to be converted to PL/SQL functions for performance reasons. We can now use connection.select\_all to grab a result set, and run it through extract objects to get a friendly active record collection (works with nested includes as well)

I have not written comprehensives tests for it yet (i know, bad!) But the source could be useful so I have decided to release it on RubyForge at [http://rubyforge.org/frs/?group\_id=4193](http://rubyforge.org/frs/?group_id=4193)

It has been working well thus far in my application, YMMV. Please give me feedback if you find any problems or have improvements.

Thanks,

Matt Kull
