title: Rails query interface is not making some associations in Rails 5.1 with API option
body: <p>I've started to transfer an old application to a new Rails application. First, i've created it with Rails 5.0, taking the same database I was using in production.  </p>
  
  <p>One of my associations is like:  </p>
  
  <pre><code>class Conta &lt; ApplicationRecord
    has_many :conta_cooperados, foreign_key: :id_conta
  end  
  
  
  class ContaCooperado &lt; ApplicationRecord
    belongs_to :conta, foreign_key: :id_conta
  end
  </code></pre>
  
  <p>If I make a query like:  </p>
  
  <pre><code>Conta.first.conta_cooperados
  </code></pre>
  
  <p>I will have the informations I wanted, and it will generate the following SQL:  </p>
  
  <pre><code>SELECT `conta_cooperado`.* FROM `conta_cooperado` WHERE `conta_cooperado`.`id_conta` = 1
  </code></pre>
  
  <p>As you can see, everything was working very well, but for some reasons I've decided to create a new application with Rails 5.1 and API option enabled.<br>
  And now, when I run the same query, the following SQL is generated:  </p>
  
  <pre><code>SELECT  `conta_cooperado`.* FROM `conta_cooperado` WHERE `conta_cooperado`.`conta_cooperado` = NULL  
  </code></pre>
  
  <p>And this one doesn't bring the expected result, because the <code>'conta_cooperado' . 'conta_cooperado' = NULL</code> part is wrong.</p>
  
  <p>I don't know if this happens because I'm using Rails 5.1 instead 5.0, or if because I'm using the api mode.</p>
  
  <p><strong>UPDATE</strong>:</p>
  
  <p>I just upgraded my Rails 5.0 application to 5.1 version, and, if until this upgrade everything was working, now I'm having the same problem. So, this situation happens only on 5.1 version of Rails. Is there a bug in this version?</p>