![]() |
|
Code snippets for symfony 1.x |
|
This is how to create a complex grouping using doctrine query.
select ... from ... where x = 1 and (a in(1,2,3) or a is not null)
class myDQ extends Doctrine_Query { public static function create($conn = null) { return new myDQ($conn); } public function toGroup() { $where = $this->_dqlParts['where']; if (count($where) > 0) { array_splice($where, count($where) - 1, 0, '('); $this->_dqlParts['where'] = $where; } return $this; } public function endGroup() { $where = $this->_dqlParts['where']; if (count($where) > 0) { $where[] = ')'; $this->_dqlParts['where'] = $where; } return $this; } }
$q = myDQ::create() ->from('Some s') ->where('s.x = ?', 1) ->andWhereIn('s.a', array(1,2,3)) ->toGroup() ->orWhere('s.a is not null') ->endGroup();