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

Closed
andreacfm opened this Issue Jan 11, 2012 · 2 comments

Projects

None yet

2 participants

@andreacfm

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 model_b.name 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?

@mislav
Owner

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 = MyModel.some_query.page(1)
p rel.to_a.size
p rel.total_entries

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

@andreacfm

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