total entries count fails when including a table with a natural primary key #222

andreacfm opened this Issue Jan 11, 2012 · 2 comments


None yet

2 participants


I have a model ( say model_a ) that has a relation like:

belongs_to :model_b, :foreign_key => :name

My issue is that when I try to sort by column will paginate does the correct sort but will not fire any query to count the total_entries.
In this way the total_entries returned is the size of the page.
I am not sure that the natural key is the culprit but any other relation that I include and sort works fine.

I am on rails 3.1.3 with sql_server.

Possibly an adapter issue?


Most of these issues are Active Record ones since will_paginate doesn't do much besides using its main query methods. Keep in mind that total_entries is a lazy method; it won't fire a query unless it's called.

I'm not sure exactly what your issue is but maybe you could illustrate it to me by calling:

rel =
p rel.to_a.size
p rel.total_entries

Of course I would need the generated SQL too from the log.


My problem is that when sorting for that particular column total_entries does not fire any query. Nothing in the log.
will_paginate will return the rows per page as total_entries.
Will try to give you more details/logs asap.

@andreacfm andreacfm closed this Jan 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment