Hi!
It would be nice to have Model\Manager option to throw an exception on model not saved instead of returning false. To me it's expected model behavior - when unexpected errors happends while working with model, it should be an exception.
Of course it could be done now with events manager like this:
$di['modelsManager'] = function () {
$eventsManager = new \Phalcon\Events\Manager();
$eventsManager->attach('model', function ($event, $model) {
if ($event->getType() == 'notSaved') {
throw new ModelException(implode(", ", $model->getMessages()));
}
});
$modelsManager = new \Phalcon\Mvc\Model\Manager();
$modelsManager->setEventsManager($eventsManager);
return $modelsManager;
};
but I'd prefer to use this way:
$di['modelsManager'] = function () {
$modelsManager = new \Phalcon\Mvc\Model\Manager();
$modelsManager->setSaveExceptions(true);
return $modelsManager;
};
and catch Model\NotSavedException using its getModel() method to get errors:
} catch (\Phalcon\Mvc\Model\NotSavedException $e) {
$exception->getModel()->getMessages();
What do you think?