ActiveRecord – Making :include and :select play nice!

So I have been using a nice plug-in that will allow me to using :select when using :include, and not have it pull the entire data set. You can add the plug-in to your app like this:

script/plugin install git://github.com/blythedunham/eload-select.git

Here are some ways to use the plug-in:

Employee.find :all,
  :select => "addresses.city, address.state, employees.*",
  :include => :address

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

Examples taken from:

http://www.snowgiraffe.com/tech/329/eager-loading-select-plugin-when-select-plays-nice-with-include/

%d bloggers like this: