sohoa/framework — pull request #80 by camael24 (2014-07-17 18:47:29+00:00)
Title: New feature for model

I think its could be cool for sohoa :)

This mix for ActiveRecord Pattern and classic mapping model

You can use both `$model['hello'] = 'world'` and `$model->insert('foo', 'bar');`

## Mapping layer
You use 4 methods `map()` , `unmap($key, $value)` , `_update(Array $array)` and `mode()`

### map()

This function must return an array which use in the model

```
public function map() {
return ['foo' => 'bar'];
}

echo $model['foo']; // bar
```
##### Pro-tip
The parameter pass on the construct will be transmit to map function
`$model = new \Application\Model\Foobar($hello, $bar);`

The function map will be execute with $this->map($hello, $bar);

### unmap($key, $value)
This function will call on each value change if you change :
```
$model['foo'] = 'bar';
$model['bar'] = 'qux';
```
Will call 2 times the function `unmap('foo' , 'bar')` and `unmap('bar', 'qux')`
Be careful for spamming !

### _update

This function will call **manually** when you call `$model->update()` function with an only one argument which contains the changed value of your model

### _static_ mode ($save, $update)

This method configue the class
$save has two values `SAVE_IMMEDIATE` and `SAVE_MANU`
$update has too two values `UPDATE_ALL_VALUE` and `UPDATE_CHANGE_VALUE`

`SAVE_IMMEDIATE` : we call **automatically** the method unmap on update value
`SAVE_MANU` : do nothing on update value, and need to call **manually** the `->update()` method

`UPDATE_ALL_VALUE` : we send all value for _update, **not** operative in immediate option !
`UPDATE_CHANGE_VALUE`: send only the changed value of your model

## ActiveRecord Pattern

Nothing on the data manipulation only some feature for send data to database, like `->sql($requete)` which accept and `\Hoa\Model\Query` object or an string, an return the instance you can combine with `all()`, `first()`, `last()`, `count()` and `item($id)` i think this is logic :p

I had a little system for logging what happens and the number of result, you can get the result with `::getSqlLog()` i think its usefull when you have tons of requetes :D

Have fun
ps : I do some test :'D, and i code that for mojo but i think its cool for sohoa
ps2 : sorry for my english and good for translate :'D