Include By Default plugin

Plugin details

This plugin allows you to specify which associations should be eager-loaded automatically when you do a +find+ on one of your models.

Websitehttp://blog.jcoglan.com/includebydefault/ Repositoryhttp://svn.jcoglan.com/includebydefault/trunk/include_by_default Author James Coglan Tags include, association LicenseMIT

Documentation

Install the plugin:
ruby script/plugin install http://svn.jcoglan.com/includebydefault/trunk/include_by_default

This saves you having to write :include all over the place to minimise your database queries. Instead, you can put whatever you'd usually specify using :include in one declaration in your model. Say you have a photoblog that allows comments. Then your entry model might look like this:

  class BlogEntry << ActiveRecord::Base
    has_many :photos
    has_many :comments
    include_by_default :photos, :comments
  end


The associations will now be loaded automatically along with any BlogEntry record you +find+. If you specify :include explicitly in any +find+ operation, that will override the default specified in the model.

Further Documentation

There is currently no advanced documentation for this plugin.

New documentation

Edit plugin | (0 older versions) | Last edited by: hardway, 7 months ago