Wait, so what exactly is the situation that's at issue here? We upgraded yesterday, too, and have both scopes and class methods that we append onto has_many/belongs_to relations, but haven't experienced anything out of the ordinary. Now I'm terrified we have some unexpected behavior lurking somewhere that's not tested or something.<p>> <i>In this case, when using the scope method to define an Arel scope on Organization, the where clause of the scope is overriding the condition imposed by the Organization#teams association. The part of the WHERE clause meant to restrict the query to Team records related to the Acme organization was dropped.</i><p>This doesn't happen in all cases -- all the cases where I've done this appears to be fine. And a scope just blowing away an association in all cases would be too obvious to not be caught.<p>Is it because both the scope and the relation select by the same attribute? Does that attribute have to be `id` for this bug to occur?<p>Or does it have to do with the fact that they're nesting a query within the where clause to determine the IDs? (I don't see why this would matter).<p>I guess I'm off to a REPL unless anyone here knows more concretely what the issue is.<p>EDIT TO ADD:<p>I can't reproduce this behavior. I just spun up a new Rails 3.2.13 app, and created those two models. Going through what they do in the console, my results differ on the potentially dangerous part:<p><pre><code> 1.9.3-p0 :015 > teams = acme.teams.using_octocats_scope
Team Load (0.3ms) SELECT "teams".* FROM "teams"
WHERE "teams"."organization_id" = 2
AND "teams"."organization_id" IN
(SELECT id FROM "organizations"
WHERE "organizations"."has_octocats" = 't')
=> []
</code></pre>
I do get an empty array, as is supposed to be the case. I notice that my nested select remains a SQL statement, rather than being evaluated to '(1)' as in their example.<p>So... I don't know if I'm doing something wrong, or if GitHub has other code / configuration settings interacting strangely here.<p>Can anyone else reproduce?<p>EDIT AGAIN:<p>Here are the four files you need to reproduce yourself. <a href="https://gist.github.com/losvedir/5202121" rel="nofollow">https://gist.github.com/losvedir/5202121</a><p>ONE MORE EDIT:<p><a href="https://github.com/losvedir/test_github_thing" rel="nofollow">https://github.com/losvedir/test_github_thing</a><p>There's a repo with my history in the console. Dunno why I'm seeing the behavior I am.