This project is archived and is in readonly mode.
count works differently than find with polymorphic include
Reported by acechase | October 3rd, 2008 @ 11:42 PM | in 3.x
It looks like AR::Base#count has different behavior than AR::Base#find when a polymorphic association is listed in the :include option. For instance, assuming with we have a class Foo, with a polymporphic association "bar", I see the following behavior:
Foo.find(:all, :include => :bar) # works fine
Foo.count(:include => :bar) # raises ActiveRecord::EagerLoadPolymorphicError
I see that ActiveRecord::Calculations::ClassMethods#count is documented to use an outer join for associations in the :include, but this feels like it is out of date in light of the changes made to the way #find makes use of the :include hash. We can already use :join in #count, so why leave the path through the :include cause as well? It feels weird that the values that are legal in the :include hash for #find are not necessarily allowed in #count. Was this a backwards compatibility issue? Maybe I'm missing something?
Comments and changes to this ticket
-
Pratik January 18th, 2009 @ 06:06 AM
- State changed from new to incomplete
- Assigned user set to Frederick Cheung
Could you please submit a failing test case ?
Assigning to Fred, as I think he added the count#:include option.
-
Jeremy Olliver June 15th, 2010 @ 11:14 AM
Trying to help out by writing a failing test case for this one, but the test I wrote passes fine. I'd like to assume this means the error is fixed in master, otherwise my test isn't right.
-
Santiago Pastorino February 2nd, 2011 @ 04:37 PM
- State changed from incomplete to open
- Importance changed from to
This issue has been automatically marked as stale because it has not been commented on for at least three months.
The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.
Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.
-
Santiago Pastorino February 2nd, 2011 @ 04:37 PM
- State changed from open to stale
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>