require-api: requireOne, requireOneByXXX, requireByArray#841
require-api: requireOne, requireOneByXXX, requireByArray#841marcj merged 1 commit intopropelorm:masterfrom
Conversation
There was a problem hiding this comment.
You could check it with $this->isWithOneToMany() and throw a exception for that case.
There was a problem hiding this comment.
This should be handled in the $this->findOne method. I just copied the description from the findOne methods because the require methods just wrap the findOne methods.
This should be fixed in it's own pull request.
|
Nice, I like it. I however don't like the term "model" in |
|
👍 for EntityNotFoundException |
|
The phpdoc of |
|
Excellent @mpscholten! When you are gonna squash those commits I'm going to merge this beauty. 😄 |
e99cff0 to
8c5ec20
Compare
|
When the discussion in #803 is finished :) But I think we will just take the I haven't rebased yet because I already use this feature and the rebase would change the commit-hash my code is requiring in the composer lock file. But here we go! :) |
Changed exception signature to match the default signature for easier reusing of existing exceptions Added requireOneBy @method annotations for better autocompletion Renamed NotFoundException to ModelNotFoundException Added missing $con argument Changed ModelNotFoundException to EntityNotFoundException
8c5ec20 to
fac953c
Compare
require-api: requireOne, requireOneByXXX, requireByArray
|
Thanks, great job :) |
Implementation of #803
This adds
requireOne(),requireOneBy($column, $value)andrequireOneByArray($values)toModelCriteria. TheModelCriteriaalso provides magic methods forrequireOneByXXXandrequireOneByXXXAndXXX. The generated query classes have@method-annotations for these magic methods to support autocompletion.You can now do something like:
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:
or by overwriting the
modelNotFoundExceptionClassattribute in your query class (or you can overwrite thecreateModelNotFoundExceptionmethod to customize your exception even more, e.g. when you use a custom constructor signature)