MaggotChild
2009-Oct-15 02:13 UTC
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.
Frederick Cheung
2009-Oct-15 07:22 UTC
Re: Select Option Broken on Eager Load With 2nd Order Association
On Oct 15, 3:13 am, MaggotChild <hsomob1...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> 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 bugWell 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
MaggotChild
2009-Oct-15 22:39 UTC
Re: Select Option Broken on Eager Load With 2nd Order Association
On Oct 15, 12:22 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Oct 15, 3:13 am, MaggotChild <hsomob1...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> 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-sqlThanks, that''s what I need.