title: Has many through with pivot table in Laravel4
body: <p>I'm trying to setup a hasManyTrough relationship with Eloquent, but it's unclear how it works from the docs.</p>
  
  <p><strong>Tables:</strong></p>
  
  <pre><code>users
     - id
     - firstname
     - ...etc
  
  accounts
     - id
     - user_id
     - username
     - ...etc
  
  roles
     - id
     - permissions
  
  account_role
     - id
     - account_id
     - role_id
  </code></pre>
  
  <p><strong>Models</strong></p>
  
  <pre><code>&lt;?php
  class User extends Eloquent {
  
      public function account()
      {
          return $this-&gt;hasOne('Account');
      }
  
      // This is what I'm trying to achieve
      public function roles()
      {
          return $this-&gt;hasManyThrough('Role', 'Account');
      }
  }
  
  class Role extends Eloquent {
  
      public function accounts()
      {
          return $this-&gt;belongsToMany('Account')-&gt;withTimestamps();
      }
  }
  
  class Account extends Eloquent {
  
      public function user()
      {
          return $this-&gt;belongsTo('User');
      }
  }
  </code></pre>
  
  <p><strong>Error and question</strong>
  The error I'm gettings is:
  <code>SQLSTATE[42S22]: Column not found: 1054 Unknown column 'roles.account_id' in 'on clause'</code></p>
  
  <p>I know I can do something <code>$user-&gt;account-&gt;roles</code>, but I want to be able to do <code>$user-&gt;roles</code>. How do I set this up properly?</p>