couchrest/couchrest_model — Issue #126: Pagination with kaminari broken when using custom view
Author: raldred
Created: 2011-11-04 15:13:42+00:00
State: open

I am experiencing issues with pagination when using a custom view

# ExamSitting Model

design do
view :by_exam_updated_at_and_completed,
:map =>
"function(doc) {
if ((doc['couchrest-type'] == 'ExamSitting') && (doc['score'] != null) && (doc['updated_at'] != null) && (doc['exam_id'] != null) && (doc['preview'] != true)) {
emit([doc['exam_id'], doc['updated_at']], null);
}
}"
end

# controller

@per_page = 10
@page = params[:page]
@exam_sittings = ExamSitting.by_exam_updated_at_and_completed.startkey([@exam.id, 0]).endkey([@exam.id, 'Z']).descending.page(@page).per(@per_page)

# view
paginate @exam_sittings

the helper prints 2 pages, when there is only 1 result.
although looking deeper into couch, it appears the total_count method is returning the wrong number of results.
Possibly something to do with lazy loading?