Skip to content

Commit 6fbdb04

Browse files
committed
Fixing tests and simplifying map reduce code in find('list')
1 parent 8e27bae commit 6fbdb04

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

lib/Cake/ORM/Table.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -530,16 +530,17 @@ public function findList(Query $query, array $options = []) {
530530
$columns = array_slice(array_keys($row), 0, 3);
531531
}
532532

533-
$key = isset($columns[2]) ? $row[$columns[2]] : $key;
534533
list($rowKey, $rowVal) = $columns;
534+
if (!isset($columns[2])) {
535+
$mr->emit($row[$rowVal], $row[$rowKey]);
536+
return;
537+
}
538+
539+
$key = $row[$columns[2]];
535540
$mr->emitIntermediate($key, [$row[$rowKey] => $row[$rowVal]]);
536541
};
537542

538543
$reducer = function($key, $values, $mr) use (&$columns) {
539-
if (!isset($columns[2])) {
540-
$mr->emit(current(current($values)), key(current($values)));
541-
return;
542-
}
543544
$result = [];
544545
foreach ($values as $value) {
545546
$result += $value;

lib/Cake/Test/TestCase/ORM/TableTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ public function testFindList() {
533533
],
534534
1 => [
535535
2 => 'nate',
536-
4 => 'garret'
536+
4 => 'garrett'
537537
]
538538
];
539539
$this->assertSame($expected, $query->toArray());

0 commit comments

Comments
 (0)