nested includes in find
October 19th, 2007 • Uncategorized
# in your model
class << self
INCLUDE_OPTIONS = [
{ :section_application => [
{ :chapter_application => [
{ :questionnaire_application => [
{ :survey_application => :survey },
:questionnaire,
] },
:chapter,
] },
:section
] },
:question,
:input_type,
:time_line,
:unit
]
def find_with_includes(*args)
find_without_includes args.pop, :include => INCLUDE_OPTIONS
end
alias_method_chain :find, :includes
end
# in your controller
def index
@models = Model.find_with_includes(:all)
end