title: HasManyThrough Relations includes a Pivot
body: <p>I have a <strong>Module</strong>, <strong>Question</strong> and <strong>Category</strong> model.</p>
  
  <pre><code>Module hasMany Questions. (1 to Many)
  Question belongsToMany Categories. (Many to Many)
  </code></pre>
  
  <p>For a given <strong>Module</strong>, I would like to access only the <strong>Questions</strong> where <strong>category_id = X</strong> .</p>
  
  <p>I'm not sure what the most efficient way of doing this is. Can I do it through a HasManyThrough relation between Module and Category? Or do I have to create a loop? Or do it through a raw SQL query?</p>
  
  <p><strong>Update</strong>:</p>
  
  <p>This SQL query seems to work. However, I'm sure there must be a more elegant solution?</p>
  
  <pre><code>SELECT id
  FROM questions
  INNER JOIN category_question ON questions.id = category_question.question_id 
  WHERE category_question.category_id = X and module_id = Y;
  </code></pre>