title: Error while using `find_or_create_by` on a `has_many` `through` association
body: <p>I am running in to a problem while using <code>find_or_create_by</code> on a <code>has_many</code>  <code>through</code> association.</p>
  
  <pre><code>class Permission &lt; ActiveRecord::Base
    belongs_to :user
    belongs_to :role
  end
  
  class Role &lt; ActiveRecord::Base
    # DB columns: user_id, role_id
  
    has_many :permissions
    has_many :users, :through =&gt; :permissions
  end
  
  class User
    has_many :permissions
    has_many :roles, :through =&gt; :permissions
  end
  </code></pre>
  
  <p>Rails throws an error when I invoke <code>find_or_create_by</code> on <code>roles</code> association of a <code>User</code> object.</p>
  
  <pre><code>u = User.first
  u.roles.find_or_create_by_rolename("admin")
  
  # Rails throws the following error
  # NoMethodError: undefined method `user_id=' for #&lt;Role id: nil, rolename: nil, 
  #  created_at: nil, updated_at: nil&gt;
  </code></pre>
  
  <p>I was able to work around the problem by changing my code as follows:</p>
  
  <pre><code>unless u.roles.exists?(:rolename =&gt; "admin")
    u.roles &lt;&lt; Role.find_or_create_by_rolename("admin") 
  end
  </code></pre>
  
  <p>I am curious to find if <code>find_or_create_by</code> works with <code>has_many</code> <code>through</code> associations. </p>