include :select if it begins with 'DISTINCT'
Reported by Chris Wanstrath | August 14th, 2007 @ 07:44 PM
I've run into a problem where, for the sake of performance, I'm using :joins rather than :include to find records with a particular association (and no, I can't reverse the situation as I'm looking for several associations at once using 'WHERE field IN (x, y, z...)' and fetching all the associated objects then iterating is even worse) . To avoid duplicates, I'm using a :select => 'DISTINCT blah' but it's not being passed to count() in will_paginate. I know we got rid of the :select option a while back (I ran into the problems it caused myself) but can we include it if it begins with 'DISTINCT'?
I've tested this out in my project and everything works fine, even the bits where :select caused problems before. Unfortunately I can't seem to get sqlite working on my machine so can't test the plugin directly.
- James Coglan
Comments and changes to this ticket
-
DEkart October 16th, 2007 @ 10:34 PM
It seems, this fix does not work. You should use 'if' statement instead of 'unless':
if options[:select] and options[:select] =~ /^\s*DISTINCT/i
excludees << :select
end
In this case this fix will work
-
Mislav October 11th, 2007 @ 03:10 PM
DEkart,
What sense does that make? My solution has unit tests that passes.
-
DEkart October 16th, 2007 @ 10:34 PM
It works fine when e have one page of data, but does not work when you have at least 2 pages.
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป
Everyone's favorite Ruby library for pagination of practically anything!