This project is archived and is in readonly mode.
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
-
gurenski May 19th, 2010 @ 02:02 AM
Thank you for noticing this issue. I'm seeing the exact same thing and its quite annoying. Any suggestions on how to fix this without having to include what's in the named scope within each instance?
-
Rizwan Reza May 21st, 2010 @ 12:47 AM
- no changes were found...
-
Marcelo Giorgi August 26th, 2010 @ 11:11 PM
- Assigned user set to Santiago Pastorino
- Tag changed from rails 2.3.5, associations, named_scope to rails 2.3.5, associations, named_scope, patch
- Importance changed from to High
Here I attach a fix for this duplication of conditions when applied to an AssociationCollection object.
This patch applies cleanly on 2-3-stable.
Please let me know any comment you may have.
-
Santiago Pastorino August 27th, 2010 @ 05:28 AM
- Milestone set to 2.3.9
- State changed from new to open
-
Santiago Pastorino September 28th, 2010 @ 07:19 PM
- Assigned user changed from Santiago Pastorino to Aaron Patterson
-
Repository September 30th, 2010 @ 05:11 PM
(from [9b78af95be01534b3f1a4187024d803313c0ee1f]) Remove duplication of conditions generated for associations when used in conjunction with named_scopes [#4634 state: resolved] http://github.com/rails/rails/commit/9b78af95be01534b3f1a4187024d80...
-
Aaron Patterson September 30th, 2010 @ 05:11 PM
- State changed from open to committed
I've applied this patch. Thanks.
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>
People watching this ticket
Attachments
Referenced by
- 4634 Duplicate association conditions are generated when using a named_scope on an association (from [9b78af95be01534b3f1a4187024d803313c0ee1f]) Remove ...