purekid / mongodm

MongoDB ORM that includes support for references,embed and multilevel inheritance.
MIT License
200 stars 47 forks source link

Fix "fieldname is not instance of 'Models\XXXXX'" error #79

Closed wildsurfer closed 9 years ago

wildsurfer commented 9 years ago

When your model has references

protected static $attrs = array(
    'number' => array('type' => 'integer'),
    'fieldname' => array('model'=>'Models\Somemodel','type'=>'reference')
);

You may face some exceptions when you try to do smth like this:

$obj = new Somemodel::id(...);
$data = $obj->toArray();
$data['number']++; 
$obj->update($data);

This PR should fix it