Exclude #reorder for count queries in Rails 3.1 #309

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
2 participants
@pawelpacana
Contributor

pawelpacana commented May 15, 2013

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
Exclude reorder for count queries.
It turns out reorder behaves differently on Rails 3.1 and requires
explicit exclude to not pollute count query with order clause.
@mislav

This comment has been minimized.

Show comment
Hide comment
@mislav

mislav Jun 21, 2013

Owner

Thanks! pulled

Owner

mislav commented Jun 21, 2013

Thanks! pulled

@mislav mislav closed this Jun 21, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment