Fixes an annoying problem with search builder
where the api gives a sql error while building your where clause.
The solution is to skip empty leaves, treating them as WIP.
*/
protected function buildWhereClause() {
foreach ($this->where as $clause) {
- $this->query->where($this->treeWalkClauses($clause, 'WHERE'));
+ $sql = $this->treeWalkClauses($clause, 'WHERE');
+ if ($sql) {
+ $this->query->where($sql);
+ }
}
}
* @uses composeClause() to generate the SQL etc.
*/
protected function treeWalkClauses($clause, $type) {
+ // Skip empty leaf.
+ if (in_array($clause[0], ['AND', 'OR', 'NOT']) && empty($clause[1])) {
+ return '';
+ }
switch ($clause[0]) {
case 'OR':
case 'AND':