title: Eloquent relation with where condition on model attribute
body: <p>I have two models <code>Student</code> and <code>StudentRevision</code> with <code>Student</code> model having <code>hasMany</code> relation with <code>StudentRevision</code> model. I have defined a <code>hasMany</code> relation in <code>Student</code> as</p>
  
  <pre><code>public function revisions()
  {
      return $this-&gt;hasMany(
          'StudentRevision',
          'sid'
      );
  }
  </code></pre>
  
  <p>I have a field in <strong>students</strong> table (Student model) which references current revision of student from <strong>student_revisions</strong> table.</p>
  
  <p>The table structure is something like this.</p>
  
  <p><strong>students</strong> sid srid name ....</p>
  
  <p><strong>student_revisions</strong> srid sid batch ....</p>
  
  <p>Now i want to define <code>hasOne</code> relation with <code>StudentRevision</code> model which references <code>current revision</code> linked with <code>Student</code>. Currently I have defined this relation as:</p>
  
  <pre><code>public function current()
  {
      return $this-&gt;hasOne(
          'StudentRevision',
          'sid'
      )
      -&gt;where('srid', $this-&gt;srid);
  }
  </code></pre>
  
  <p>But the problem with this relation is, that <code>$this-&gt;srid</code> is not available during query building process and can be only there after the actual model is available.</p>
  
  <p>Please help how to overcome this.</p>