fuel/orm — pull request #290 by jraede (2013-08-25 20:41:06+00:00)
Title: Pagination refactor

ORM query pagination has always had issues when adding relations to the mix. This fixes that by avoiding the use of LIMIT and OFFSET, and rather just adding one extra query to retrieve the primary keys of all matching main (first-level) models, and then adding a where condition for {PRIMARY_KEY} IN ($values), where $values is the paginated set of primary key results.

So basically, no more need for subqueries, it functions the same as \Orm\Query::count() in terms of query generation, and just applies pagination based on the desired position in the full primary key result set.

Example:

```
$query = \Model\Paycheck::query()->related('employee')->related('company')->where('company.city', 'Los Angeles');

// This is optional - if you don't provide an instance of \Fuel\Core\Pagination then the add_pagination method
// will create one on the variable passed by reference to the method (third argument)
$pagination = \Pagination::forge('my-pagination', array(
'pagination_url'=>'/paycheck/index',
'uri_segment'=>'page'
));

$results = $query->order_by('employee.name')->apply_pagination(\Input::get('page', 1), 20, $pagination)->get();
```