This project is archived and is in readonly mode.
collection_singular_ids breaks when used with :include
Reported by Diego Algorta | July 9th, 2009 @ 09:30 PM | in 3.x
Given a has_many association defined with an :include option, you can't use the #collection_singular_ids method because it fails trying to eager load the 2nd level association when it's unneeded.
The attached patch includes a test case where you can see the need for it.
I'm not exactly happy with the patch because it involves adding a new :ignore_include valid option to ActiveRecord::Base.find, but I think I've read people requesting that kind of option too so maybe this is something you may want too.
Please review the patch and suggest any improvements or raise concerns.
Comments and changes to this ticket
-
Michael Koziarski August 3rd, 2009 @ 06:11 AM
- Tag changed from :include, activerecord, eager_loading, patch to :include, activerecord, bugmash, eager_loading, patch
-
dira August 9th, 2009 @ 12:51 PM
verified
Updated just the tests from the patch to apply cleanly.
I think there should be a cleaner implementation - so I did not include the original one in the patch.
-
Jason Roelofs November 19th, 2009 @ 07:05 PM
I just ran into this bug. Asking for collection_singular_ids shouldn't try to load any include-ed associations.
-
Rizwan Reza February 12th, 2010 @ 12:46 PM
- Tag changed from :include, activerecord, bugmash, eager_loading, patch to :include, activerecord, eager_loading, patch
-
Dan Pickett May 9th, 2010 @ 07:18 PM
- Tag changed from :include, activerecord, eager_loading, patch to :include, activerecord, bugmash, eager_loading, patch
Can a bugmasher verify this errant behavior on master and supply an updated path?
-
Diego Algorta May 10th, 2010 @ 09:27 AM
- Assigned user set to Jeremy Kemper
I'm attaching two separate patches in case the core team doesn't like my fix, or someone shows up with a better one (which is quite possible).
add_failing_singular_ids_with_include_test.diff is an updated version of the failing test needed to prove the bug.
fix_failing_singular_ids_with_include.diff is the patch to fix activerecord so that the previously added test, passes. It's VERY different from my original patch when creating this ticket as rails itself has changed a lot since then. I still think someone with better knowledge of activerecord's internals could do it better, but this one seems to be good enough (and I think less messy than the previous one).
Both apply cleanly on top of ce5827ea4791e8b8143919ecceb0231e36e8932e (master from may 9)
-
Diego Algorta May 11th, 2010 @ 12:36 AM
I forgot to include one file in the test patch, So I'm attaching a new commit with the missing file.
-
Diego Algorta May 11th, 2010 @ 12:47 AM
- no changes were found...
-
Federico Brubacher May 11th, 2010 @ 01:26 AM
The last patch looks much better than the first time, i ran the tests on latest version of master and so far so good. It seems a issue worth fixing.
+1 -
Diego Algorta May 11th, 2010 @ 07:24 PM
As there where too many patch files already, I deleted the ones which were mine and I'm submitting them merged in just 2 files.
- 1-new_failing_test.diff adds a new test to demonstrate the bug.
- 2-fix-bug.diff fixes the bug, gets the test to pass. Maybe someone can think of a better fix, but I think this one is good enough.
-
José Valim May 15th, 2010 @ 03:35 PM
- Tag changed from :include, activerecord, bugmash, eager_loading, patch to :include, activerecord, eager_loading, patch
- State changed from new to verified
- Assigned user changed from Jeremy Kemper to Pratik
Assigning to Pratik since he knows better about ActiveRecord.
-
Diego Algorta May 15th, 2010 @ 03:42 PM
- Tag changed from :include, activerecord, eager_loading, patch to :include, activerecord, bugmash, eager_loading, patch
- Assigned user changed from Pratik to Jeremy Kemper
I've attached a patch.
As requested by rizwanreza on #railsbridge, I'm attaching a merged patch with both the test and the fix in just one commit. Rebased to latest master branch.
-
Rizwan Reza May 15th, 2010 @ 03:49 PM
- Assigned user changed from Jeremy Kemper to Pratik
-
Diego Algorta May 15th, 2010 @ 04:40 PM
I've attached a patch.
This new patch has a way much simpler test and fix. Thx Pratik for pointing me to the right direction as the old patch and fix were based on the initial work for rails 2.3
-
Repository May 15th, 2010 @ 04:59 PM
- State changed from verified to resolved
(from [3436fdfc12d58925e3d981e0afa61084ea34736c]) Fix for get_ids when including a belongs_to association on a has_many association [#2896 state:resolved]
Signed-off-by: Pratik Naik pratiknaik@gmail.com
http://github.com/rails/rails/commit/3436fdfc12d58925e3d981e0afa610... -
Rizwan Reza May 15th, 2010 @ 05:21 PM
- Tag changed from :include, activerecord, bugmash, eager_loading, patch to :include, activerecord, eager_loading, patch
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
- 2896 collection_singular_ids breaks when used with :include (from [3436fdfc12d58925e3d981e0afa61084ea34736c]) Fix for...