Answer the question
In order to leave comments, you need to log in
What is the correct way to design a repository for use with optional parameters?
you need to get a list in which there is a mandatory parameter, as well as pass some additional optional parameters that narrow the selection
. For example, the getAllOrdersByCompany method (company id is required in this case),
but you may additionally need to pass a date or something else ....
I don’t want to fence a bunch of methods in the controller / repository or fence IF, SWITCH
Is it possible to solve this problem somehow gracefully?
Answer the question
In order to leave comments, you need to log in
Gracefully solves the Criteria/Specification pattern.
Doctrine Specification Pattern or yours are reusable...
It may be complicated, but it does your job elegantly. Fortunately, it is already packaged in the library, which you will find at the link above.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question