In Codeigniter (PHP framework), I am trying to create a helper function that will inject an ActiveRecord (for MySQL) command into a chain of existing ActiveRecord calls. The reasoning for this is that the current ActiveRecord commands available are not reliable enough, and produce differing results depending on what parameters are passed in.
$param = "";
WHERE `field` = ""
This would provide a result set where only blank fields were returned.
This is not always the intended behavior, as the input comes from a web form, and may be the result of no specific query being submitted - thus all results should be returned instead.
What I decided to come up with, was a helper method that would take in a set of unknown inputs, and return a result set that would match my desired behavior (eg. return all results or return none).
Using test cases and a test method to abstract the desired set of inputs and outputs away, I hoped to produce an easy-to-call method for coercing the database results into my desired behavior. This would be easier then say, coercing the input into an expected type, and then using the unreliable behavior of Codeigniter's ActiveRecord commands.
My main concern however, is that my helper function may be trying to do too much - my colleague described it as a magic method that takes anything and may have arcane implementation details. It would thus be less readable than the ActiveRecord convention (which is more well-known) and harder to maintain.
Is my function the best way to go about it, or are there better alternatives out there?