title: Laravel 3 Eloquent ORM for 3 level relation & filter
body: <p>I had 3 models:</p>
  
  <p><strong>model A</strong>:</p>
  
  <pre><code>class A extends \Eloquent {
      ...
      public function Bs() {
          return $this-&gt;belongsTo('B','B_id','id');
      }
      public function Xs() {
          return $this-&gt;belongsTo('X','X_id','id');
      }
      public function Ys() {
          return $this-&gt;belongsTo('Y','Y_id','id');
      }
      ...
  }
  </code></pre>
  
  <p><strong>model B</strong>:</p>
  
  <pre><code>    class B extends \Eloquent {
          ...
      public function As()
      {
              return $this-&gt;hasMany('A');
      }
          public function Cs()
          {
              return $this-&gt;hasMany('C');
      }
          ...
     }
  </code></pre>
  
  <p><strong>model C</strong>:   </p>
  
  <pre><code> class c extends \Eloquent {
          ...
      public function Bs()
      {
              return $this-&gt;belongsTo('B','B_id','id');
      }
      public function Zs()
      {
              return $this-&gt;belongsTo('Z','Z_id','id');
      }
          ...
     }
  </code></pre>
  
  <p>I need all data of <strong>A</strong> with filters on X, Y and Z. Then I added <code>hasManyThrough()</code> to <strong>C</strong> like this;</p>
  
  <p><strong>model C</strong>:</p>
  
  <pre><code>    class c extends \Eloquent {
          ...
      public function Bs()
      {
              return $this-&gt;belongsTo('B','B_id','id');
      }
      public function Zs()
      {
              return $this-&gt;belongsTo('Z','Z_id','id');
      }
      public function As()
      {
              return $this-&gt;hasManyThrough('A','B','id','B_id');
      }
          ...
     }
  </code></pre>
  
  <p>But when I fetch the data using controller like this:</p>
  
  <pre><code> public function index()
   {
  
   $output=C::where('Z_id','=',Input::get('Z'))
      -&gt;with('As');
   ...
   }
  </code></pre>
  
  <p>It gives me blank out put for <strong>As</strong></p>
  
  <pre><code>[As] =&gt; Array
        (
        }
  </code></pre>
  
  <p>*****EDIT 1******
  Table Details
  <br>
  Here are they<br>
  <strong>Table A</strong> | <strong>JobOpening</strong> | id | title | city_id | type | company_id <br>
  <strong>Table B</strong> | <strong>Company</strong> | id | name | websiteaddress <br>
  <br>
  Company has many Job Openings <br>
  <br>
  <strong>Table C</strong> | <strong>CompanyIndustry</strong> | id | type | company_id | industry_id <br>
  And may be part of many Industry Sector.  <br>
  type is either 1 or 2, where 1 means primary and 2 means other <br>
  <br>
  <strong>Table D</strong> | <strong>Industry</strong> | id | name   <br>
  master table of all industry names <br>
  eg. Service, Fashion, etc. <br></p>