diff --git a/cake/libs/model/model.php b/cake/libs/model/model.php index d6ecb4f95..4efd06c6f 100644 --- a/cake/libs/model/model.php +++ b/cake/libs/model/model.php @@ -739,18 +739,6 @@ class Model extends Overloadable { function set($one, $two = null) { if (is_object($one)) { $one = Set::reverse($one); - $count = count($one); - for ($i = 0; $i < $count; $i++) { - if(isset($one[$i])){ - if($i === 0) { - $one[$this->name] = $one[$i]; - } else { - $name = array_keys($one[$i]); - $one[$name[0]] = $one[$i][$name[0]]; - } - unset($one[$i]); - } - } } if (is_array($one)) { diff --git a/cake/libs/set.php b/cake/libs/set.php index e11ca23b0..37645f606 100644 --- a/cake/libs/set.php +++ b/cake/libs/set.php @@ -682,7 +682,9 @@ class Set extends Object { for ($i = 0; $i < $count; $i++) { if ($keys[$i] == '__identity__') { + $key = $object[$keys[$i]]; unset($object[$keys[$i]]); + $object[$key] = $object; } elseif (is_array($object[$keys[$i]])) { $keys1 = array_keys($object[$keys[$i]]); $count1 = count($keys1); @@ -701,11 +703,28 @@ class Set extends Object { } } $return = $object; + if(!empty($merge)) { - $object = array($object, $merge); + $mergeKeys = array_keys($merge); + $objectKeys = array_keys($object); + $count = count($mergeKeys); + $change = $object; + + for ($i = 0; $i < $count; $i++) { + foreach ($objectKeys as $key => $value) { + if(is_array($object[$value])) { + if(array_key_exists($mergeKeys[$i], $object[$value])) { + unset($change[$value][$mergeKeys[$i]]); + } + } else { + unset($change[$value]); + } + } + } + $object = Set::pushDiff($change, $merge); } return $object; } } } -?> +?> \ No newline at end of file diff --git a/cake/tests/cases/libs/set.test.php b/cake/tests/cases/libs/set.test.php index 534a3914c..804204601 100644 --- a/cake/tests/cases/libs/set.test.php +++ b/cake/tests/cases/libs/set.test.php @@ -438,6 +438,75 @@ class SetTest extends UnitTestCase { ); $this->assertIdentical($result, $expected); } -} + function testMapReverse() { + $expected = array('Array1' => array( + 'Array1Data1' => 'Array1Data1 value 1', + 'Array1Data2' => 'Array1Data2 value 2', + 'Array1Data3' => 'Array1Data3 value 3', + 'Array1Data4' => 'Array1Data4 value 4', + 'Array1Data5' => 'Array1Data5 value 5', + 'Array1Data6' => 'Array1Data6 value 6', + 'Array1Data7' => 'Array1Data7 value 7', + 'Array1Data8' => 'Array1Data8 value 8'), + + 'Array2' => array( + 0 => array( + 'Array2Data1' => 1, + 'Array2Data2' => 'Array2Data2 value 2', + 'Array2Data3' => 'Array2Data3 value 2', + 'Array2Data4' => 'Array2Data4 value 4'), + 1 => array( + 'Array2Data1' => 2, + 'Array2Data2' => 'Array2Data2 value 2', + 'Array2Data3' => 'Array2Data3 value 2', + 'Array2Data4' => 'Array2Data4 value 4'), + 2 => array( + 'Array2Data1' => 3, + 'Array2Data2' => 'Array2Data2 value 2', + 'Array2Data3' => 'Array2Data3 value 2', + 'Array2Data4' => 'Array2Data4 value 4'), + 3 => array( + 'Array2Data1' => 4, + 'Array2Data2' => 'Array2Data2 value 2', + 'Array2Data3' => 'Array2Data3 value 2', + 'Array2Data4' => 'Array2Data4 value 4'), + 4 => array( + 'Array2Data1' => 5, + 'Array2Data2' => 'Array2Data2 value 2', + 'Array2Data3' => 'Array2Data3 value 2', + 'Array2Data4' => 'Array2Data4 value 4')), + + 'Array3' => array( + 0 => array( + 'Array3Data1' => 1, + 'Array3Data2' => 'Array3Data2 value 2', + 'Array3Data3' => 'Array3Data3 value 2', + 'Array3Data4' => 'Array3Data4 value 4'), + 1 => array( + 'Array3Data1' => 2, + 'Array3Data2' => 'Array3Data2 value 2', + 'Array3Data3' => 'Array3Data3 value 2', + 'Array3Data4' => 'Array3Data4 value 4'), + 2 => array( + 'Array3Data1' => 3, + 'Array3Data2' => 'Array3Data2 value 2', + 'Array3Data3' => 'Array3Data3 value 2', + 'Array3Data4' => 'Array3Data4 value 4'), + 3 => array( + 'Array3Data1' => 4, + 'Array3Data2' => 'Array3Data2 value 2', + 'Array3Data3' => 'Array3Data3 value 2', + 'Array3Data4' => 'Array3Data4 value 4'), + 4 => array( + 'Array3Data1' => 5, + 'Array3Data2' => 'Array3Data2 value 2', + 'Array3Data3' => 'Array3Data3 value 2', + 'Array3Data4' => 'Array3Data4 value 4'))); + + $map = Set::map($expected); + $result = Set::reverse($map); + $this->assertIdentical($result, $expected); + } +} ?> \ No newline at end of file