title: find_or_create_by multiple attributes not finding records when called in context of belongs_to object (AR bug in 2.3.11?)
body: <p>I am adding omniauth to a rails 2.3.11 application with devise. I'm basically following Ryan Bate's <a href="http://railscasts.com/episodes/235-omniauth-part-1" rel="nofollow">railscast</a> (with appropriate modifications for rails 2.3). But I'm seeing something very odd in testing this part of the code:</p>
  
  <pre><code>class AuthenticationsController &lt; ApplicationController
    ...
  
    def create
      auth = request.env["omniauth.auth"]
      current_user.authentications.find_or_create_by_provider_and_uid(auth['provider'], auth['uid'])
      flash[:notice] = "Authentication successful."
      redirect_to authentications_url
    end
  
    ...
  end
  </code></pre>
  
  <p>The find_or_create always creates. In the log, I see this select:</p>
  
  <pre><code>SELECT * FROM `authentications` WHERE (`authentications`.`provider` IN ('facebook','XXXXXXX') AND `authentications`.`uid` IS NULL) AND ((`authentications`.`user_id` = 10)) LIMIT 1
  </code></pre>
  
  <p>That is not the right select for that method. auth['provider'] and auth['uid'] are populated correctly (and it creates the new record just fine).</p>
  
  <p>More perplexing: If I go into the console and do <code>Authentication.find_or_create_by_provider_and_uid('facebook', 'XXXXX')</code>, it works fine (it finds the existing record). But if I get a user and do <code>user.authentications.find_or_create_by_provider_and_uid('facebook', 'XXXXX')</code>, it creates a new record and I see the same problematic query statement in the log.</p>
  
  <p>I know I can work around this (and Ryan Bates changes this code later anyway), but this is very troubling. Am I missing something or does this look like a bug in ActiveRecord?</p>
  
  <p>This is not specific to OmniAuth or Devise. Before submitting this, I tried it with two other classes (rather simple classes). Same result [ Klass.find_or_create_by_a_and_b('A','B') works but parent.klasses.find_or_create_by_a_and_b('A','B') generates a select that wants b to be null and a in ('A','B')].</p>
  
  <p>Now I'm definitely thinking this is a bug 2.3.11. Before I submit a bug, does anybody see anything I'm missing? Has anyone seen this problem?</p>