Module | WillPaginate::Finders::Base |
In: |
lib/will_paginate/finders/base.rb
|
Out of the box, will_paginate supports hooking in several ORMs to provide paginating finders based on their API. As of this writing, the supported libraries are:
It‘s easy to write your own adapter for anything that can load data with explicit limit and offset settings. DataMapper adapter is a nice and compact example of writing an adapter to bring the paginate method to DataMapper models.
In most ORMs, :order parameter specifies columns for the ORDER BY clause in SQL. It is important to have it, since pagination only makes sense with ordered sets. Without the order clause, databases aren‘t required to do consistent ordering when performing SELECT queries.
Ordering by a field for which many records share the same value (e.g. "status") can still result in incorrect ordering with some databases (MS SQL and Postgres for instance). With these databases it‘s recommend that you order by primary key as well. That is, instead of ordering by "status DESC", use the alternative "status DESC, id DESC" and this will yield consistent results.
Therefore, make sure you are doing ordering on a column that makes the most sense in the current context. Make that obvious to the user, also. For perfomance reasons you will also want to add an index to that column.
This is the main paginating finder.
All other options (conditions, order, …) are forwarded to find and count calls.
Iterates through all records by loading one page at a time. This is useful for migrations or any other use case where you don‘t want to load all the records in memory at once.
It uses paginate internally; therefore it accepts all of its options. You can specify a starting page with :page (default is 1). Default :order is "id", override if necessary.
Jamis Buck describes this and also uses a more efficient way for MySQL.