UnionOfRAD/lithium — pull request #328 by Daikoun (2012-02-13 01:15:32+00:00)
Title: Data: fixed & optimized conditional operation mapping, schema reference on Document->set() [third one]

Condition operation mapping:
=====================
The conditions mapping using operation did not worked properly.
If you define e.g. something like this:
```
group::count(array('_id' => array('$ne' => this->request->id))); //id is a string
```
in the mapped query the id remains as string, which looks like this:
```
'conditions' => array(
'_id' => array('$ne' => $id) //where $id represents the given id, which still remains as string
)
```

if I use the alias '!=' instead of the mongo operation '$ne':
```
group::count(array('_id' => array('!=' => this->request->id))); //id is a string
```
the id will be mapped but the query structure is not compatible to the mongo php driver:
```
'conditions' => array(
'_id' => array('$ne' => array('_id' => MongoId($id))) //where $id represents the given id string
)
```

The fix solves the compatibility bug no matter if the Mongo operation or the alias will be used and optimizes the operation mapping function.
Result:
```
'conditions' => array(
'_id' => array('$ne' => MongoId($id)) //where $id represents the given id string
)
```
Test cases are still implemented in MongoDbTest but failed in previous version.

Schema reference:
==============

This is the third pull request

If I set a value in a document like this:
```
$group->created = '';
```
and there is a schema defined in the specific model, like this
```
protected $_schema = array(
'created' => array('type' => 'date', 'default' => ''),
);
```
the value should be converted to the specified type, which did not happened caused by a wrong reference call to the schema of parent class Entity instead of the model.

Corresponding Test Cases:
====================

Test cases added. I've extended the `MockMongoPost` to simply add a static schema definition like the definition in a specific model class because in `MongoDbTest` the schema assignment to mock models still do not work. Maybe this is caused by instantiating `lithium\data\Schema` instead of `lithium\data\source\mongo_db\Schema`, but I'm not sure. What I found out is, that in `lithium\data\Schema` the function `schema()` do not append schema fields (it should, as described in the documentation), which also influences the `config()` of `Query` in where corresponding function is called.

The modification in `Entity->schema()` means, that the schema of assigned model should have a higher priority than the autoconfig schema of `Entity` (which contains at least only the definition for `_id`). The schema from corresponding model must be called because `source->item()` contains the parameter for the model only, not the schema to initialize. This causes autoload of default schema in Entity that means there still exists a schema and the case for `this->schema` in Entity (current HEAD version) is always called and the 2nd case for loading schema from model will not be entered.