mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-02-07 12:36:25 +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)) {
|
if (is_object($out)) {
|
||||||
$out = get_object_vars($out);
|
$out = get_object_vars($out);
|
||||||
}
|
}
|
||||||
$out[$key] = Set::__map($value, $class, true);
|
$out[$key] = Set::__map($value, $class);
|
||||||
} elseif ($primary === true && is_array($value)) {
|
if (is_object($out[$key])) {
|
||||||
$out->_name_ = $key;
|
if ($primary !== true && is_array($value) && Set::countDim($value, true) == 2) {
|
||||||
$primary = false;
|
$out[$key]->_name_ = $primary;
|
||||||
foreach($value as $key2 => $value2) {
|
}
|
||||||
$out->{$key2} = Set::__map($value2, true);
|
}
|
||||||
|
} elseif (is_array($value)) {
|
||||||
|
if ($primary === true) {
|
||||||
|
$out->_name_ = $key;
|
||||||
|
$primary = false;
|
||||||
|
foreach($value as $key2 => $value2) {
|
||||||
|
$out->{$key2} = Set::__map($value2, true);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
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 {
|
} else {
|
||||||
$out->{$key} = Set::__map($value, $class);
|
$out->{$key} = $value;
|
||||||
if (is_object($out->{$key})) {
|
|
||||||
$out->{$key}->_name_ = $key;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1694,11 +1694,10 @@ class SetTest extends CakeTestCase {
|
||||||
$expected->Author->updated = "2007-03-17 01:18:31";
|
$expected->Author->updated = "2007-03-17 01:18:31";
|
||||||
$expected->Author->test = "working";
|
$expected->Author->test = "working";
|
||||||
$expected->Author->_name_ = 'Author';
|
$expected->Author->_name_ = 'Author';
|
||||||
|
|
||||||
$this->assertIdentical($expected, $result);
|
$this->assertIdentical($expected, $result);
|
||||||
|
|
||||||
//Case where extra HABTM fields come back in a result
|
//Case where extra HABTM fields come back in a result
|
||||||
$result = Set::map(array(
|
$data = array(
|
||||||
'User' => array(
|
'User' => array(
|
||||||
'id' => 1,
|
'id' => 1,
|
||||||
'email' => 'user@example.com',
|
'email' => 'user@example.com',
|
||||||
|
@ -1711,39 +1710,70 @@ class SetTest extends CakeTestCase {
|
||||||
'title' => 'Moonlight Sonata',
|
'title' => 'Moonlight Sonata',
|
||||||
'composer' => 'Ludwig van Beethoven',
|
'composer' => 'Ludwig van Beethoven',
|
||||||
'PiecesUser' => array(
|
'PiecesUser' => array(
|
||||||
'id' => 2,
|
'id' => 1,
|
||||||
'created' => '2008-01-01 00:00:00',
|
'created' => '2008-01-01 00:00:00',
|
||||||
'modified' => '2008-01-01 00:00:00',
|
'modified' => '2008-01-01 00:00:00',
|
||||||
'piece_id' => 1,
|
'piece_id' => 1,
|
||||||
'user_id' => 2,
|
'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 = new stdClass();
|
||||||
$expected->_name_ = 'User';
|
$expected->_name_ = 'User';
|
||||||
$expected->id = 1;
|
$expected->id = 1;
|
||||||
$expected->email = 'user@example.com';
|
$expected->email = 'user@example.com';
|
||||||
$expected->first_name = 'John';
|
$expected->first_name = 'John';
|
||||||
$expected->last_name = 'Smith';
|
$expected->last_name = 'Smith';
|
||||||
|
|
||||||
$piece = new stdClass();
|
$piece = new stdClass();
|
||||||
$piece->_name_ = 'Piece';
|
|
||||||
$piece->id = 1;
|
$piece->id = 1;
|
||||||
$piece->title = 'Moonlight Sonata';
|
$piece->title = 'Moonlight Sonata';
|
||||||
$piece->composer = 'Ludwig van Beethoven';
|
$piece->composer = 'Ludwig van Beethoven';
|
||||||
|
|
||||||
$piece->PiecesUser = new stdClass();
|
$piece->PiecesUser = new stdClass();
|
||||||
$piece->PiecesUser->_name_ = 'PiecesUser';
|
$piece->PiecesUser->id = 1;
|
||||||
$piece->PiecesUser->id = 2;
|
|
||||||
$piece->PiecesUser->created = '2008-01-01 00:00:00';
|
$piece->PiecesUser->created = '2008-01-01 00:00:00';
|
||||||
$piece->PiecesUser->modified = '2008-01-01 00:00:00';
|
$piece->PiecesUser->modified = '2008-01-01 00:00:00';
|
||||||
$piece->PiecesUser->piece_id = 1;
|
$piece->PiecesUser->piece_id = 1;
|
||||||
$piece->PiecesUser->user_id = 2;
|
$piece->PiecesUser->user_id = 2;
|
||||||
|
$piece->PiecesUser->_name_ = 'PiecesUser';
|
||||||
|
|
||||||
|
$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);
|
||||||
|
|
||||||
$expected->Piece = array($piece);
|
|
||||||
|
|
||||||
$this->assertIdentical($expected, $result);
|
$this->assertIdentical($expected, $result);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue