Skip to content
Permalink
Browse files

Reversing params for mapReduce in Table class

  • Loading branch information...
lorenzo committed Dec 31, 2013
1 parent edd811b commit 5daddf33be0c8c61bb8e9a583b016d4e7f9ae6b0
Showing with 7 additions and 7 deletions.
  1. +7 −7 Cake/ORM/Table.php
@@ -739,7 +739,7 @@ public function findList(Query $query, array $options = []) {
'valueField' => $this->displayField(),
'groupField' => false
];
$mapper = function($key, $row, $mapReduce) use ($options) {
$mapper = function($row, $key, $mapReduce) use ($options) {
$rowKey = $options['idField'];
$rowVal = $options['valueField'];
if (!($options['groupField'])) {
@@ -748,10 +748,10 @@ public function findList(Query $query, array $options = []) {
}
$key = $row[$options['groupField']];
$mapReduce->emitIntermediate($key, [$row[$rowKey] => $row[$rowVal]]);
$mapReduce->emitIntermediate([$row[$rowKey] => $row[$rowVal]], $key);
};
$reducer = function($key, $values, $mapReduce) {
$reducer = function($values, $key, $mapReduce) {
$result = [];
foreach ($values as $value) {
$result += $value;
@@ -776,13 +776,13 @@ public function findList(Query $query, array $options = []) {
public function findThreaded(Query $query, array $options = []) {
$parents = [];
$hydrate = $query->hydrate();
$mapper = function($key, $row, $mapReduce) use (&$parents) {
$mapper = function($row, $key, $mapReduce) use (&$parents) {
$row['children'] = [];
$parents[$row['id']] =& $row;
$mapReduce->emitIntermediate($row['parent_id'], $row['id']);
$mapReduce->emitIntermediate($row['id'], $row['parent_id']);
};
$reducer = function($key, $values, $mapReduce) use (&$parents, $hydrate) {
$reducer = function($values, $key, $mapReduce) use (&$parents, $hydrate) {
if (empty($key) || !isset($parents[$key])) {
foreach ($values as $id) {
$parents[$id] = $hydrate ? $parents[$id] : new \ArrayObject($parents[$id]);
@@ -798,7 +798,7 @@ public function findThreaded(Query $query, array $options = []) {
$query->mapReduce($mapper, $reducer);
if (!$hydrate) {
$query->mapReduce(function($key, $row, $mapReduce) {
$query->mapReduce(function($row, $key, $mapReduce) {
$mapReduce->emit($row->getArrayCopy());
});
}

0 comments on commit 5daddf3

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