title: activerecord where clause on relation belongs_to
body: <p>I'm not strong in sql and relatively new to rails.  The </p>
  
  <pre><code>Case
    attr_accessible client_id
    belongs_to Client
  
  Client
    attr_accessibe name
    has_many Cases
  </code></pre>
  
  <p>I can query directly by client_id and get a record back as expected</p>
  
  <pre><code>Case.where(client_id: 1)
  </code></pre>
  
  <p>But I would like to query by client.name </p>
  
  <pre><code>Case.where(client.name =&gt; "Foo")
  </code></pre>
  
  <p>This give me an error that tells me that client is not a method of case.</p>
  
  <pre><code>Undefined method or local variable 
  </code></pre>
  
  <p>Ultimately, what I'm trying to do is very simple: get the first Case that belongs to client "Foo".  The query I would expect to use is this.</p>
  
  <pre><code>Case.where(client.name =&gt; "Foo").first
  </code></pre>
  
  <p>What should it be?</p>