:include, , , , , , " />

Eager loading Select Plugin: when :select plays nice with :include

March 26, 2009

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:

  1. Works with aliases and database functions
  2. Employee.find :first,
      :select => 'now() as current_time, addresses.city, DATE(addresses.created_at) as addresses.created_at, employee.*'
      :include => :address
  3. Plays nice with other plugins like ar-extensions
  4. Selects columns on the base table (some options force you to select all of the base table)
  5. 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.

Leave a Reply