#234 √ resolved
Eduardo

count in paginate(:include => ...) uses join but it's not needed

Reported by Eduardo | June 28th, 2008 @ 10:35 AM

Hi,

I have Programs and Ower (Program belongs to Owner and to System).

If I have a system object (id=4)and do system.programs.paginate(:include => :owner) I get the following SQL to count the registers:

SELECT count(DISTINCT `programs`.id) AS count_all FROM `programs` LEFT OUTER JOIN `owners` ON `owners`.id = `programs`.owner_id WHERE (`programs`.system_id = 4)

I didn't do copy paste because the models where in another language, so I changed the original sql to match this example.

The question is, couldn't you simply count without taking the :include into account? It looks like overkill to me.

By the way, Active Record is no longer using joins for :include, it actually gets all the programs, and then it fetches the owners with the IN(a,b,c) sql operator. Unless there is a condition on the include table, that is.

It does this:

SELECT * FROM `programs` WHERE (`programs`.system_id = 4)

SELECT * FROM `owners` WHERE (`owners`.id IN ('33','43','32'))

This is a great plugin!

Eduardo.

Comments and changes to this ticket

  • Mislav

    Mislav June 30th, 2008 @ 03:05 PM

    • → State changed from “new” to “resolved”

    Hey. That's a good idea and we already discussed and hacked it -- see #198

    Watch that ticket for updates, please. It will be in the next version of will_paginate.

Please Login or create a free account to add a new comment.

You can update this ticket by sending an email to from your email client. (help)

Create your profile

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

Shared Ticket Bins

People watching this ticket