Skip to content

Commit

Permalink
Fixing tests and simplifying map reduce code in find('list')
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Aug 15, 2013
1 parent 8e27bae commit 6fbdb04
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions lib/Cake/ORM/Table.php
Expand Up @@ -530,16 +530,17 @@ public function findList(Query $query, array $options = []) {
$columns = array_slice(array_keys($row), 0, 3);
}

$key = isset($columns[2]) ? $row[$columns[2]] : $key;
list($rowKey, $rowVal) = $columns;
if (!isset($columns[2])) {
$mr->emit($row[$rowVal], $row[$rowKey]);
return;
}

$key = $row[$columns[2]];
$mr->emitIntermediate($key, [$row[$rowKey] => $row[$rowVal]]);
};

$reducer = function($key, $values, $mr) use (&$columns) {
if (!isset($columns[2])) {
$mr->emit(current(current($values)), key(current($values)));
return;
}
$result = [];
foreach ($values as $value) {
$result += $value;
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Test/TestCase/ORM/TableTest.php
Expand Up @@ -533,7 +533,7 @@ public function testFindList() {
],
1 => [
2 => 'nate',
4 => 'garret'
4 => 'garrett'
]
];
$this->assertSame($expected, $query->toArray());
Expand Down

0 comments on commit 6fbdb04

Please sign in to comment.