Default :include value for ActiveRecord::Base.find

Hi all,

I'm working on a application with lots of complicated data
relationships and thousands of rows of data. To speed up queries, I'm
using Project.find(:all, :conditions => some_hash, :include =>
some_other_hash). I'm using the same hash for :include quite a lot -
is there a way to specify in the Project model that it should use a
certain :include hash in find() by default so I can DRY up my code?

Thanks,
James

Hi

You can always define a class method for Project that wraps the find,
something like (warn absolutely untested)

class Project
  def self.find_std_include(*args)
    options = {:include => your_standard_include_hash}
    if args.last.is_a? Hash
      options.update(args.pop)
    end
    self.find(*args.push(options))
  end
end

This way you can call Project.find_std_include() every time you need
to use the standard include clause.

Paolo

Thanks Paolo. I figured a class method was probably the way to go, but
was wondering if there was any way of modifying the default behaviour
of find() on a per-class basis. Thanks for the help.