From ec6f75a7b456388022dd49703480bfeca520ebd5 Mon Sep 17 00:00:00 2001 From: Simon JAILLET Date: Tue, 18 Dec 2012 00:48:30 +0100 Subject: [PATCH] Close #732. --- data/DocumentSchema.php | 2 +- .../data/source/mongo_db/ExporterTest.php | 20 ++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/data/DocumentSchema.php b/data/DocumentSchema.php index 7d8859950f..b97cb32abb 100644 --- a/data/DocumentSchema.php +++ b/data/DocumentSchema.php @@ -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'; } diff --git a/tests/cases/data/source/mongo_db/ExporterTest.php b/tests/cases/data/source/mongo_db/ExporterTest.php index f303962361..902f80061e 100644 --- a/tests/cases/data/source/mongo_db/ExporterTest.php +++ b/tests/cases/data/source/mongo_db/ExporterTest.php @@ -757,7 +757,7 @@ public function testIndexesOnExportingDocument() { 'accounts' => array(array( '_id' => "4fb6e2dd3e91581fe6e75736", 'name' => 'Foo1' - ),array( + ), array( '_id' => "4fb6e2df3e91581fe6e75737", 'name' => 'Bar1' )) @@ -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); + } } ?> \ No newline at end of file