Close #732. #748

Merged
merged 1 commit into from Dec 18, 2012
@@ -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';
}
@@ -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);
+ }
}
?>