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.









--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to