Skip to content
Permalink
Browse files

Add finder options to Paginator->paginate method

The paginator right now doesn't send $options to any finder, custom or otherwise. This change allows setting 'finderOptions' directly from the controller's paginate array.
  • Loading branch information...
Patrick Conroy
Patrick Conroy committed Aug 25, 2014
1 parent f13c341 commit 56d6f04136b553b1a2ee46c7cedd3b9ca801ce63
@@ -164,7 +164,7 @@ public function paginate($object, array $settings = []) {
unset($options['finder'], $options['maxLimit']);
if (empty($query)) {
$query = $object->find($type);
$query = $object->find($type, $options);
}
$query->applyOptions($options);
@@ -141,6 +141,27 @@ public function testPaginateExtraParams() {
$this->Paginator->paginate($table, $settings);
}
/**
* Test to make sure options get sent to custom finder methods via paginate
* @return void
*/
public function testPaginateCustomFinderOptions() {
$this->loadFixtures('Post');
$settings = [
'PaginatorPosts' => [
'finder' => 'author',
'author_id' => 1
]
];
$table = TableRegistry::get('PaginatorPosts');
$expected = $table->find('author', ['conditions' => ['PaginatorPosts.author_id' => $settings['PaginatorPosts']['author_id']]])
->count();
$result = $this->Paginator->paginate($table, $settings)->count();
$this->assertEquals($expected, $result);
}
/**
* Test that special paginate types are called and that the type param doesn't leak out into defaults or options.
*
@@ -52,4 +52,18 @@ public function findPublished(Query $query, array $options) {
return $query;
}
/**
* Custom finder, used with fixture data to ensure Paginator is sending options
*
* @param Cake\ORM\Query $query
* @param array $options
* @return Cake\ORM\Query
*/
public function findAuthor(Query $query, array $options = []) {
if (isset($options['author_id'])) {
$query->where(['PaginatorPosts.author_id' => $options['author_id']]);
}
return $query;
}
}

0 comments on commit 56d6f04

Please sign in to comment.
You can’t perform that action at this time.