Eager loading Select Plugin: when :select plays nice with :include
With ActiveRecord::Base.find, :select is ignored when :include is specified. There’s been many a ticket and proposed but denied patch and google discussion to provide this functionality.
eload-select plugin to the rescue!
Employee.find :all, :select => 'addresses.city, address.state, employees.*', :include => :address
The advantages of the eload-select plugin:
- Works with aliases and database functions
- Plays nice with other plugins like ar-extensions
- Selects columns on the base table (some options force you to select all of the base table)
Employee.find :first, :select => 'now() as current_time, addresses.city, DATE(addresses.created_at) as addresses.created_at, employee.*' :include => :address
Employee.find :all, :select => 'addresses.city, employees.name, employees.start_date', :include => :address
script/plugin install git://github.com/blythedunham/eload-select.git
And your off! Recently updated to work with all versions of rails including 2.3.


[...] if for instance you were only interested in for instance the city. To achieve this, I updated the eload select plugin. It does use some tricky parsing but does have the advantage of accepting aliases and allowing you [...]
[...] Examples taken from http://www.snowgiraffe.com/tech/329/eager-loading-select-plugin-when-select-plays-nice-with-include/ [...]