Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close #732. #748

Merged
merged 1 commit into from Dec 18, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion data/DocumentSchema.php
Expand Up @@ -67,7 +67,7 @@ protected function _castArray($object, $val, $pathKey, $options, $defaults) {
$numericArray = !$val || array_keys($val) === range(0, count($val) - 1);
}

if (($isArray && !$isObject) || $numericArray) {
if ($isArray || ($numericArray && !$isObject)) {
$val = $valIsArray ? $val : array($val);
$class = 'set';
}
Expand Down
20 changes: 19 additions & 1 deletion tests/cases/data/source/mongo_db/ExporterTest.php
Expand Up @@ -757,7 +757,7 @@ public function testIndexesOnExportingDocument() {
'accounts' => array(array(
'_id' => "4fb6e2dd3e91581fe6e75736",
'name' => 'Foo1'
),array(
), array(
'_id' => "4fb6e2df3e91581fe6e75737",
'name' => 'Bar1'
))
Expand All @@ -779,6 +779,24 @@ public function testIndexesOnExportingDocument() {
$this->assertTrue(isset($result['update']['accounts'][0]));
$this->assertTrue(isset($result['update']['accounts'][1]));
}

public function testEmptyArrayAsDocument() {
$schema = new Schema(array('fields' => array(
'_id' => array('type' => 'id'),
'accounts' => array('type' => 'object', 'array' => true),
'accounts.name' => array('type' => 'string')
)));

$data = array(
'_id' => '4c8f86167675abfabd970300',
'accounts' => array(array())
);

$model = $this->_model;

$document = new Document(compact('model', 'schema', 'data'));
$this->assertTrue($document->accounts[0] instanceof Document);
}
}

?>