Created
March 2, 2018 20:46
-
-
Save jackdpeterson/11f132d0f4a45f96816dcde36f824a02 to your computer and use it in GitHub Desktop.
When you are using the where In SQL-like search and provide an empty array for the in side of things ... DQL will barf and die with a syntax error. The fix is to check the count of items in the parameter being passed in and create a single entry with a non-possible value to filter down. /** * Creates an IN() expression with the given arguments. …
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Creates an IN() expression with the given arguments. | |
* | |
* @param string $x Field in string format to be restricted by IN() function. | |
* @param mixed $y Argument to be used in IN() function. | |
* | |
* @return Expr\Func | |
*/ | |
public function in($x, $y) | |
{ | |
if (is_array($y)) { | |
foreach ($y as &$literal) { | |
if ( ! ($literal instanceof Expr\Literal)) { | |
$literal = $this->_quoteLiteral($literal); | |
} | |
} | |
} | |
return new Expr\Func($x . ' IN', (array) $y); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment