propelorm/Propel2 — pull request #841 by mpscholten (2014-12-10 17:02:36+00:00)
Title: require-api: requireOne, requireOneByXXX, requireByArray

Implementation of #803

This adds `requireOne()`, `requireOneBy($column, $value)` and `requireOneByArray($values)` to `ModelCriteria`. The `ModelCriteria` also provides magic methods for `requireOneByXXX` and `requireOneByXXXAndXXX`. The generated query classes have `@method`-annotations for these magic methods to support autocompletion.

---

You can now do something like:

```php
requireOneById($_GET['id'])->getName();
} catch (\Propel\Runtime\Exception\ModelNotFoundException $e) {
echo $e->getMessage();
}
```

Which will output 'Hello Marc' or 'User could not be found' depending on whenever the given user-id exists.

---

You can customize the exception class in the propel config:
```yaml
propel
generator:
objectModel:
notFoundExceptionClass: \Vendor\Project\ResourceNotFoundException
```
or by overwriting the `modelNotFoundExceptionClass` attribute in your query class (or you can overwrite the `createModelNotFoundException` method to customize your exception even more, e.g. when you use a custom constructor signature)