# Select Option Broken on Eager Load With 2nd Order Association

**URL:** <https://www.ruby-forum.com/t/select-option-broken-on-eager-load-with-2nd-order-association/177330>\
**Category:** Rails\
**Created:** [October 15, 2009, 4:15am UTC](https://www.ruby-forum.com/t/select-option-broken-on-eager-load-with-2nd-order-association/177330 "2009-10-15T04:15:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MaggotChild](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7ea924/32.png) [@MaggotChild](https://www.ruby-forum.com/u/MaggotChild)\
**Post date:** [October 15, 2009, 4:15am UTC](https://www.ruby-forum.com/t/select-option-broken-on-eager-load-with-2nd-order-association/177330/1 "2009-10-15T04:15:23Z")

</div>

I only want to select certain columns when eager loading an  
association:

class Package \< ActiveRecord::Base  
has\_many :deliveries,  
:select=\>‘id, name, region\_id, package\_id’, #exclude text  
column dont\_select\_me  
:include=\>:region  
end

class Delivery \< ActiveRecord::Base  
belongs\_to :package  
belongs\_to :region  
end

Package.first :include =\> :deliveries

Generates the correct SQL:  
SELECT TOP 1 \* FROM [packages]  
SELECT id, name, region\_id, package\_id FROM [deliveries] WHERE  
([deliveries].package\_id = 1)  
SELECT \* FROM [regions] WHERE ([regions].[id] = 1)

But, when I say:

Package.first :include =\> :deliveries, :conditions =\> “deliveries.name  
= ‘shlomo’”

The SQL is:

SELECT [packages].[id] AS t0\_r0, [packages].[name] AS t0\_r1,  
[packages].[created\_at] AS t0\_r2,  
[packages].[updated\_at] AS t0\_r3, [deliveries].[id] AS t1\_r0,  
[deliveries].[name] AS t1\_r1,  
[deliveries].[created\_at] AS t1\_r2, [deliveries].[updated\_at] AS  
t1\_r3, [deliveries].[dont\_select\_me] AS t1\_r4,  
[deliveries].[region\_id] AS t1\_r5, [deliveries].[package\_id] AS  
t1\_r6  
FROM [packages] LEFT OUTER JOIN [deliveries] ON deliveries.package\_id  
= packages.id WHERE (deliveries.name = “delivery”) AND [packages].id  
IN (1)

dont\_select\_me is included. The docs say nothing of about :select  
being stepped on by fall back left joins (not the :include!). This  
seems like a bug.

---

<div class="post-metadata">

**Author:** ![MaggotChild](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7ea924/32.png) [@MaggotChild](https://www.ruby-forum.com/u/MaggotChild)\
**Post date:** [October 15, 2009, 9:24am UTC](https://www.ruby-forum.com/t/select-option-broken-on-eager-load-with-2nd-order-association/177330/2 "2009-10-15T09:24:27Z")

</div>

On Oct 15, 3:13 am, MaggotChild [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> dont\_select\_me is included. The docs say nothing of about :select  
> being stepped on by fall back left joins (not the :include!). This  
> seems like a bug

Well the docs should say that - it has always been that way. You need  
something like [http://www.kellogg-assoc.com/2006/11/05/eager-finder-sql](http://www.kellogg-assoc.com/2006/11/05/eager-finder-sql)  
(don’t know if it is still maintained)

Fred

---

<div class="post-metadata">

**Author:** ![MaggotChild](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7ea924/32.png) [@MaggotChild](https://www.ruby-forum.com/u/MaggotChild)\
**Post date:** [October 16, 2009, 12:40am UTC](https://www.ruby-forum.com/t/select-option-broken-on-eager-load-with-2nd-order-association/177330/3 "2009-10-16T00:40:36Z")

</div>

On Oct 15, 12:22 am, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> On Oct 15, 3:13 am, MaggotChild [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > dont\_select\_me is included. The docs say nothing of about :select  
> > being stepped on by fall back left joins (not the :include!). This  
> > seems like a bug
> 
> Well the docs should say that - it has always been that way. You need  
> something likehttp://www.kellogg-assoc.com/2006/11/05/eager-finder-sql

Thanks, that’s what I need.
