This project is archived and is in readonly mode.

#4634 ✓committed
Joseph Palermo

Duplicate association conditions are generated when using a named_scope on an association

Reported by Joseph Palermo | May 18th, 2010 @ 12:52 AM | in 2.3.10

Probably not a bug, as it does not change the behavior. But I spent the afternoon tracking down why my association conditions were being applied twice in the query, so hopefully this ticket will prevent others from wasting an afternoon.

#1960 introduced this behavior.

So when you do Foo.my_assoc.my_scope:
When my_scope gets constructed it is within the scope of my_assoc, so it saves that scope's finder conditions internally. When you then evaluate the scope and the association to fetch records, my_assoc and my_scope both apply the association finder conditions separately so you end up with it twice in your query.

I'm guessing this is fixed in rails 3 by arel, but I have not checked.

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Attachments

Referenced by

Pages