Skip to content
Permalink
Browse files

Fixing Set::extract run against hasMany records that are the result o…

…f a find('first'). Test case added.
  • Loading branch information...
markstory committed Sep 1, 2009
1 parent 86f2008 commit fb476f17cc0d5285235704ba1f9ec603a441ec5b
Showing with 19 additions and 1 deletion.
  1. +1 −1 cake/libs/set.php
  2. +18 −0 cake/tests/cases/libs/set.test.php
@@ -387,7 +387,7 @@ function extract($path, $data = null, $options = array()) {
$options = array_merge(array('flatten' => true), $options);
if (!isset($contexts[0])) {
$current = current($data);
if ((is_array($current) && count($data) <= 1) || !is_array($current)) {
if ((is_array($current) && count($data) <= 1) || !is_array($current) || !Set::numeric(array_keys($data))) {
$contexts = array($data);
}
}
@@ -993,6 +993,24 @@ function testExtract() {
$expected = array(array('name' => 'zipfile.zip','type' => 'application/zip','tmp_name' => '/tmp/php178.tmp','error' => 0,'size' => '564647'));
$r = Set::extract('/file/.[type=application/zip]', $f);
$this->assertEqual($r, $expected);
$hasMany = array(
'Node' => array(
'id' => 1,
'name' => 'First',
'state' => 50
),
'ParentNode' => array(
0 => array(
'id' => 2,
'name' => 'Second',
'state' => 60,
)
)
);
$result = Set::extract('/ParentNode/name', $hasMany);
$expected = array('Second');
$this->assertEqual($result, $expected);
}
/**
* testMatches method

0 comments on commit fb476f1

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