mislav/will_paginate — pull request #309 by pawelpacana (2013-05-15 08:36:06+00:00)
Title: Exclude #reorder for count queries in Rails 3.1

It turns out reorder behaves differently on Rails 3.1 and requires
explicit exclude to not pollute count query with order clause.

This is a especially a problem when reordering on aggregate column form original query, i.e.:

```

>> Shop.with_ticket_types.reorder('ticket_types_count').page(1)

SELECT shops.*, COUNT(product_types.id) ticket_types_count FROM `shops` INNER JOIN `product_types` ON `product_types`.`shop_id` = `shops`.`id` GROUP BY shops.id ORDER BY ticket_types_count LIMIT 30 OFFSET 0
SELECT COUNT(*) AS count_all, shops.id AS shops_id FROM `shops` INNER JOIN `product_types` ON `product_types`.`shop_id` = `shops`.`id` GROUP BY shops.id ORDER BY ticket_types_count

Mysql2::Error: Unknown column 'ticket_types_count' in 'order clause': SELECT COUNT(*) AS count_all, shops.id AS shops_id FROM `shops` INNER JOIN `product_types` ON `product_types`.`shop_id` = `shops`.`id` GROUP BY shops.id ORDER BY ticket_types_count
```