Skip to content

Commit

Permalink
Bug in casting subobject arrays solve #471
Browse files Browse the repository at this point in the history
  • Loading branch information
jails committed May 23, 2012
1 parent 5cb1229 commit 581a11a
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions data/DocumentSchema.php
Expand Up @@ -42,7 +42,12 @@ public function cast($object, $data, array $options = array()) {

foreach ($data as $key => $val) {
$fieldName = is_int($key) ? null : $key;
$pathKey = $basePathKey ? "{$basePathKey}.{$fieldName}" : $fieldName;

if($fieldName) {
$pathKey = $basePathKey ? "{$basePathKey}.{$fieldName}" : $fieldName;
} else {
$pathKey = $basePathKey;
}

if ($val instanceof $classes['array'] || $val instanceof $classes['entity']) {
continue;
Expand Down Expand Up @@ -82,7 +87,7 @@ protected function _castArray($object, $val, $pathKey, $options, $defaults) {
}

if ($options['wrap']) {
$config = array('data' => $val, 'model' => $options['model']);
$config = array('data' => $val, 'model' => $options['model'], 'schema' => $this);
$config += compact('pathKey') + array_diff_key($options, $defaults);
$val = $this->_instance($class, $config);
}
Expand Down

0 comments on commit 581a11a

Please sign in to comment.