From 8b8463686f6f679a9b34426a391a0417948ae6bc Mon Sep 17 00:00:00 2001 From: Nicolas Buduroi Date: Sat, 3 Dec 2011 17:23:28 -0500 Subject: [PATCH] Fixed count method to handle result from grouped relations. --- lib/will_paginate/active_record.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/will_paginate/active_record.rb b/lib/will_paginate/active_record.rb index a5c1ecd86..88eee506e 100644 --- a/lib/will_paginate/active_record.rb +++ b/lib/will_paginate/active_record.rb @@ -65,7 +65,9 @@ def count rel = self.except(*excluded) # TODO: hack. decide whether to keep rel = rel.apply_finder_options(@wp_count_options) if defined? @wp_count_options - rel.count + result = rel.count + # TODO: hack. handle count result returned by grouped relation + result.is_a?(Hash) ? result.values.reduce(&:+) : result else super end