I'm using will_paginate to display data returned from a query that includes both a joins and a select statement. When I paginate the data the number of entries is equal to the number of entries before executing the select statement, even though paginate is being called after the query, and the query contains fewer elements than paginate reports.
@sales = Sale.joins(:line_items).where(company_id: company_id, status: ['Complete', 'Voided'], time: (midnight_1..midnight_2)).order('id DESC')
puts @sales.length
14
@sales = @sales.select('distinct sales.*')
puts @sales.length
4
@sales.paginate(:per_page => 4, :page => params[page])
puts @sales.total_entries
14
This leads to displaying links to empty pages.
:count => {:group
option is exactly what we were looking for! Thanks :) Is this in the docs somewhere? – Spellbind