Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

count works differently than find with polymorphic include

#1166

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?

Reported by acechase · October 3rd, 2008 @ 11:42 PM

State: stale
Milestone: 3.x
Assigned to: Frederick Cheung Frederick Cheung
Importance: none

Activity

  1. Pratik
    Pratik
    • 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.

    January 18th, 2009 @ 06:06 AM

  2. Ryan Bigg
    Ryan Bigg

    Fred, any news on this? I can still replicate it in 2.3.5.

    April 10th, 2010 @ 11:20 AM

  3. Jeremy Kemper
    Jeremy Kemper
    • Milestone changed from 2.x to 3.x

    May 4th, 2010 @ 06:48 PM

  4. Jeremy Olliver
    Jeremy Olliver

    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.

    June 15th, 2010 @ 11:14 AM

  5. Santiago Pastorino
    Santiago Pastorino
    • 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.

    February 2nd, 2011 @ 04:37 PM

  6. Santiago Pastorino
    Santiago Pastorino
    • State changed from open to stale

    February 2nd, 2011 @ 04:37 PM