mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
fixing bug in Set:map() handling of recursive records
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7531 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
84b6d1b66c
commit
dde620edb4
2 changed files with 66 additions and 23 deletions
|
@ -187,18 +187,31 @@ class Set extends Object {
|
|||
if (is_object($out)) {
|
||||
$out = get_object_vars($out);
|
||||
}
|
||||
$out[$key] = Set::__map($value, $class, true);
|
||||
} elseif ($primary === true && is_array($value)) {
|
||||
$out[$key] = Set::__map($value, $class);
|
||||
if (is_object($out[$key])) {
|
||||
if ($primary !== true && is_array($value) && Set::countDim($value, true) == 2) {
|
||||
$out[$key]->_name_ = $primary;
|
||||
}
|
||||
}
|
||||
} elseif (is_array($value)) {
|
||||
if ($primary === true) {
|
||||
$out->_name_ = $key;
|
||||
$primary = false;
|
||||
foreach($value as $key2 => $value2) {
|
||||
$out->{$key2} = Set::__map($value2, true);
|
||||
}
|
||||
} else {
|
||||
$out->{$key} = Set::__map($value, $class);
|
||||
if (is_object($out->{$key})) {
|
||||
if (!is_numeric($key)) {
|
||||
$out->{$key} = Set::__map($value, true, $key);
|
||||
if (is_object($out->{$key}) && !is_numeric($key)) {
|
||||
$out->{$key}->_name_ = $key;
|
||||
}
|
||||
} else {
|
||||
$out->{$key} = Set::__map($value, true);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$out->{$key} = $value;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -1694,11 +1694,10 @@ class SetTest extends CakeTestCase {
|
|||
$expected->Author->updated = "2007-03-17 01:18:31";
|
||||
$expected->Author->test = "working";
|
||||
$expected->Author->_name_ = 'Author';
|
||||
|
||||
$this->assertIdentical($expected, $result);
|
||||
|
||||
//Case where extra HABTM fields come back in a result
|
||||
$result = Set::map(array(
|
||||
$data = array(
|
||||
'User' => array(
|
||||
'id' => 1,
|
||||
'email' => 'user@example.com',
|
||||
|
@ -1711,15 +1710,29 @@ class SetTest extends CakeTestCase {
|
|||
'title' => 'Moonlight Sonata',
|
||||
'composer' => 'Ludwig van Beethoven',
|
||||
'PiecesUser' => array(
|
||||
'id' => 2,
|
||||
'id' => 1,
|
||||
'created' => '2008-01-01 00:00:00',
|
||||
'modified' => '2008-01-01 00:00:00',
|
||||
'piece_id' => 1,
|
||||
'user_id' => 2,
|
||||
)
|
||||
),
|
||||
array(
|
||||
'id' => 2,
|
||||
'title' => 'Moonlight Sonata 2',
|
||||
'composer' => 'Ludwig van Beethoven',
|
||||
'PiecesUser' => array(
|
||||
'id' => 2,
|
||||
'created' => '2008-01-01 00:00:00',
|
||||
'modified' => '2008-01-01 00:00:00',
|
||||
'piece_id' => 2,
|
||||
'user_id' => 2,
|
||||
)
|
||||
));
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$result = Set::map($data);
|
||||
|
||||
$expected = new stdClass();
|
||||
$expected->_name_ = 'User';
|
||||
|
@ -1729,20 +1742,37 @@ class SetTest extends CakeTestCase {
|
|||
$expected->last_name = 'Smith';
|
||||
|
||||
$piece = new stdClass();
|
||||
$piece->_name_ = 'Piece';
|
||||
$piece->id = 1;
|
||||
$piece->title = 'Moonlight Sonata';
|
||||
$piece->composer = 'Ludwig van Beethoven';
|
||||
|
||||
$piece->PiecesUser = new stdClass();
|
||||
$piece->PiecesUser->_name_ = 'PiecesUser';
|
||||
$piece->PiecesUser->id = 2;
|
||||
$piece->PiecesUser->id = 1;
|
||||
$piece->PiecesUser->created = '2008-01-01 00:00:00';
|
||||
$piece->PiecesUser->modified = '2008-01-01 00:00:00';
|
||||
$piece->PiecesUser->piece_id = 1;
|
||||
$piece->PiecesUser->user_id = 2;
|
||||
$piece->PiecesUser->_name_ = 'PiecesUser';
|
||||
|
||||
$expected->Piece = array($piece);
|
||||
$piece->_name_ = 'Piece';
|
||||
|
||||
|
||||
$piece2 = new stdClass();
|
||||
$piece2->id = 2;
|
||||
$piece2->title = 'Moonlight Sonata 2';
|
||||
$piece2->composer = 'Ludwig van Beethoven';
|
||||
|
||||
$piece2->PiecesUser = new stdClass();
|
||||
$piece2->PiecesUser->id = 2;
|
||||
$piece2->PiecesUser->created = '2008-01-01 00:00:00';
|
||||
$piece2->PiecesUser->modified = '2008-01-01 00:00:00';
|
||||
$piece2->PiecesUser->piece_id = 2;
|
||||
$piece2->PiecesUser->user_id = 2;
|
||||
$piece2->PiecesUser->_name_ = 'PiecesUser';
|
||||
|
||||
$piece2->_name_ = 'Piece';
|
||||
|
||||
$expected->Piece = array($piece, $piece2);
|
||||
|
||||
$this->assertIdentical($expected, $result);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue