UnionOfRAD/lithium — Issue #299: General schema definition not working in DocumentArray
Author: Daikoun
Created: 2012-01-26 07:38:39+00:00
State: open

The schema definition will not be assigned DocumentArrays.

Test-schema:
```
protected $_schema = array(
'name' => array('type' => 'string'),
'created' => array('type' => 'date', 'default'=>''),
'members' => array('type' => 'array', 'array' => true),
'members.user_id' => array('type' => 'id'),
'members.timestamp' => array('type' => 'date', 'default' => ''),
'members.status' => array('type' => 'string'),
);
```
Test add data:
```
$group = Groups::create();
$group->members[] = array('user_id' => $user->_id, 'status' => 'blocked')
```

First of all after calling `create()`, `members` is of the correct type `DocumentArray` but contains already the defaults, which looks like a normal Subdocument. If I add an entry to DocumentArray (Test line: 2), it is appended in members as `DocumentArray` with key `0` after the defaults. The defaults are also not assigned to the entry.

Result:
```
[members] : DocumentArray
|- [_data]
| |- [timestamp] : MongoDate
| |- [0] : DocumentArray
| | |- [user_id]
| | |- [status]
```
I've tested to define a schema for a specific Index of an array, like this:
```
'members.0.user_id' => array('type' => 'id'),
'members.0.timestamp' => array('type' => 'date', 'default' => ''),
'members.0.status' => array('type' => 'string'),
```
the defaults are working correctly, but that's not my desired solution.

Expected Result:
If I define a DocumentArray in the schema, I will not define the schema for every index (thats exactly like I define x Subdocuments), just a general definition for every entry in the DocumentArray. The defaults should also only be assigned, if an entry will be added to the array.