title: How to put conditions on associated records?
body: <p>Here are my models:</p>
  
  <pre><code>class Checklist &lt; ActiveRecord::Base
      has_many :checklists_tasks
      has_many :tasks, through: :checklists_tasks
  end
  
  class ChecklistsTask &lt; ActiveRecord::Base
      belongs_to :checklist
      belongs_to :task
  end
  
  class Section &lt; ActiveRecord::Base
      has_many :tasks
  end
  
  class Task &lt; ActiveRecord::Base
      belongs_to :section
      has_many :checklists_tasks
      has_many :checklists, through: :checklists_tasks
  end
  </code></pre>
  
  <p>I then have a view like this:</p>
  
  <pre><code>&lt;% @sections.each do |section| %&gt;
      &lt;h2&gt;&lt;%= section.name %&gt;&lt;/h2&gt;
      &lt;ul&gt;
      &lt;% section.tasks.each.do |task| %&gt;
          &lt;li&gt;&lt;%= task.name %&gt;&lt;/li&gt;
      &lt;% end %&gt;
      &lt;/ul&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>How do I query Section and make sure that the tasks associated with each Section are all associated with a certain Checklist?</p>
  
  <p>To clarify, /checklists/1/show and /checklists/2/show should use the view above and ouput the same sections, but the tasks in the sections could be different.</p>