My app receives an identifier that could match one of two fields in a table. Rather than to blindly check for a match on either, I would like to modify the query in the Table’s beforeFind function. If the identifier looks like a username, I’ll leave the query alone. If it looks like the alternate field, I want to remove the username condition from the query and add the alternate condition. I don’t see any way to change or remove a where condition from a query, though. Am I missing something?
The $query->where()
method has an $overwrite
parameter which lets you replace all of the conditions with new ones. This might let you do what you want if you need to replace the conditions entirely.
@markstory: I did find that in the source, but $overwrite doesn’t change
the placeholders in the SQL, so while I can replace or remove one or
more parameter values, I cannot remove it entirely from the SQL.
Removing a parameter value without removing the placeholder from the SQL
of course generates an exception.
I have found a workaround in my app to remove this need, but I’m still
curious about this question.