Create a search criteria with optional keys

See this
http://doctrine-orm.readthedocs.org/en/latest/reference/working-with-associations.html?highlight=criteria#filtering-collections

If I want to create a criteria with optional keys sent by restapi request with doctrine to search a user via restapi request, I can use “where” and “andWhere” to create criteria with values sent by api request. I can use separate If statement to see if an optional key, e.g. email, username etc. is present to add a “andWhere” clause? Good idea? But how to add a “where” clause at first as I don’t know what is present in request? If I check with a if statement with a long || clause to see if any key is present, add that one to “where” clause, then later might be a duplicate “andWhere” clause with the same thing like email or username. Please advice how to solve this? How to solve this with either criteria or findBy()?
The problem is that all email, usernam, createdDate between X and Y, …, are optional and how to know what are present to make that Criteria?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.