Skip to content
Permalink
Browse files

adding doc blocks for new finders

  • Loading branch information...
lorenzo committed Aug 20, 2013
1 parent 5b862d5 commit 1ae0413f5a96424b5f65b6b87c431a08e5c283ed
Showing with 38 additions and 2 deletions.
  1. +33 −2 lib/Cake/ORM/Table.php
  2. +5 −0 lib/Cake/Test/TestCase/ORM/TableTest.php
@@ -513,8 +513,7 @@ public function find($type, $options = []) {
}
/**
* Applies the options required to find all records on this table based
* on the passed options.
* Returns the query as passed
*
* @param \Cake\ORM\Query $query
* @param array $options
@@ -524,6 +523,27 @@ public function findAll(Query $query, array $options = []) {
return $query;
}
/**
* Sets up a query object so results appear as an indexed array, useful for any
* place where you would want a list such as for populating input select boxes.
*
* When calling this finder, the fields passed are used to determine what should
* be used as the array key, value and optionally what to group the results by.
* By default the primary key for the model is used for the key, and the display
* field.
*
* The results of this finder will be in the following form:
*
* [
* 1 => 'value for id 1',
* 2 => 'value for id 2',
* 4 => 'value for id 4'
* ]
*
* @param \Cake\ORM\Query $query
* @param array $options
* @return \Cake\ORM\Query
*/
public function findList(Query $query, array $options = []) {
$mapper = function($key, $row, $mr) use (&$columns) {
if (empty($columns)) {
@@ -551,6 +571,17 @@ public function findList(Query $query, array $options = []) {
return $query->mapReduce($mapper, $reducer);
}
/**
* Results for this finder will be a nested array, and is appropriate if you want
* to use the parent_id field of your model data to build nested results.
*
* Values belonging to a parent row based on their parent_id value will be
* recursively nested inside the parent row values using the `children` property
*
* @param \Cake\ORM\Query $query
* @param array $options
* @return \Cake\ORM\Query
*/
public function findThreaded(Query $query, array $options = []) {
$parents = [];
$mapper = function($key, $row, $mr) use (&$parents) {
@@ -539,6 +539,11 @@ public function testFindList() {
$this->assertSame($expected, $query->toArray());
}
/**
* Tests find('threaded')
*
* @return void
*/
public function testFindThreaded() {
$table = new Table(['table' => 'categories', 'connection' => $this->connection]);
$expected = [

0 comments on commit 1ae0413

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