nested includes in find

# 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


Leave a Reply

Formatting: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>