title: Eloquent Nested Relation with Some Constraint
body: <p>I have the following three tables:</p>
  
  <pre><code>A
  -------------
  | id | name |
  -------------
  
  B
  --------------------
  | id | A_id | name |
  --------------------
  
  C
  --------------------
  | id | B_id | name |
  --------------------
  </code></pre>
  
  <p>So, the data in table <code>C</code> belongs to the data in table <code>B</code> which belongs to the data in table <code>A</code>. Now, I want to query <code>C</code>, while also retrieving data from <code>B</code> and <code>A</code> and the following code does the trick just fine.</p>
  
  <pre><code>C::with('B.A')-&gt;get();
  </code></pre>
  
  <p>The problem now, is that I want to query <code>C</code> with some constraints. One of these constraints is the <code>id</code> of <code>A</code>. I've tried the following:</p>
  
  <pre><code>C::with(array('B.A' =&gt; function ($query)
  {
      $query-&gt;where('id', '=', $constraint);
  }))-&gt;get();
  </code></pre>
  
  <p>But it seems that Eloquent will retrieve all the rows in <code>C</code> without even taking the constraint into account, except when it's executing the query to retrieve data in table <code>A</code>. How do I get around this problem? Do I need to add another field in <code>C</code>, that is <code>A_id</code>, and match <code>$constraint</code> against that field?</p>