mislav/will_paginate — Issue #202: Impossible to configure the column to use for the Distinct close
Author: eltados
Created: 2011-11-17 23:29:26+00:00
State: open

I have a model Page with a number of column one of which is a column containing very big entry

Therefore i want to specify the select clause in order to exclude this column ( for obvious performance reason )

pages.order("created_at desc").paginate(:page => params[:page], :per_page => 7).select("`pages`.`id`, `pages`.`url`, `pages`.`title`, `pages`.`author`, `pages`.`date`, `pages`.`text`, `pages`.`media`, `pages`.`type`, `pages`.`image_url`, `pages`.`image_height`, `pages`.`image_width`, `pages`.`created_at`, `pages`.`updated_at`, `pages`.`image_file_name`, `pages`.`image_content_type`, `pages`.`image_file_size`, `pages`.`image_updated_at`, `pages`.`debug`, `pages`.`published_at`")

Generates

SELECT DISTINCT `pages`.*, `pages`.`id`, `pages`.`url`, `pages`.`title`, `pages`.`author`, `pages`.`date`, `pages`.`text`, `pages`.`media`, `pages`.`type`, `pages`.`image_url`, `pages`.`image_height`, `pages`.`image_width`, `pages`.`created_at`, `pages`.`updated_at`, `pages`.`image_file_name`, `pages`.`image_content_type`, `pages`.`image_file_size`, `pages`.`image_updated_at`, `pages`.`debug`, `pages`.`published_at` FROM `pages` ORDER BY created_at desc LIMIT 7 OFFSET 28

The problem is that will_paginate generate DISTINCT `pages`.* which load all. Is there a way to specify the column to use for the DISCTINCT ? I could not find anything on the Net or reading the source code.

I know that this problem can be solved by extracting out this large column out of the table but this out of the possibility now because many ( good and bad ) internal reasons.