Select Option Broken on Eager Load With 2nd Order Association

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.

On Oct 15, 3:13 am, MaggotChild [email protected] 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
(don’t know if it is still maintained)

Fred

On Oct 15, 12:22 am, Frederick C. [email protected]
wrote:

On Oct 15, 3:13 am, MaggotChild [email protected] 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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs