Hey Guys, I can't figure out how I can add parenthesis to generate a statement like one below in ZF2:
*EXAMPLE1:* SELECT "persons".* FROM "persons" WHERE *(*"givenName" LIKE '%john%' OR "surname" LIKE '%john%' OR "givenName" LIKE '%doe%' OR "surname" LIKE '%doe%'*)* AND active = 1 ORDER BY "surname" ASC LIMIT '2' OFFSET '0' The code below generates the following sql statement: * EXAMPLE2:* SELECT "persons".* FROM "persons" WHERE "givenName" LIKE '%john%' OR "surname" LIKE '%john%' OR "givenName" LIKE '%doe%' OR "surname" LIKE '%doe%' AND active = 1 ORDER BY "surname" ASC LIMIT '2' OFFSET '0' $spec = function (Where $where) use ($keywords) { foreach( $keywords as $value ) { $where->like('givenName',"%$value%"); $where->OR; $where->like('surname',"%$value%"); $where->OR; } }; $select->where($spec); $select->where('active = 1'); $select->order('surname ASC'); $select->offset($start); $select->limit($count); On this one I can't figure out how I can insert "(...)" in between I've tried to add nest but it just creates "()" in between conditions. I have also tried the following code but it generates this SQL: *EXAMPLE3:* SELECT "persons".* FROM "persons" WHERE ("givenName" LIKE '%john%' *AND* "surname" LIKE '%john%' *AND* "givenName" LIKE '%doe%' *AND* "surname" LIKE '%doe%') *AND OR* AND active = 1 ORDER BY "surname" ASC LIMIT '2' OFFSET '0' $predicates = array(); foreach( $keywords as $value ) { $predicates[] = new Predicate\Like('givenName',"%$value%"); $predicates[] = new Predicate\Like('surname',"%$value%"); } $select->where(array( new Predicate\PredicateSet($predicates), Predicate\PredicateSet::OP_OR )); $select->where('active = 1'); $select->order('surname ASC'); $select->offset($start); $select->limit($count); On this one I can't figure out how I can change "AND" to "OR" in between (...) and eliminate the "AND OR" Anyone have insights? -- View this message in context: http://zend-framework-community.634137.n4.nabble.com/Help-using-predicate-and-nesting-conditions-tp4659776.html Sent from the Zend Framework mailing list archive at Nabble.com. -- List: fw-general@lists.zend.com Info: http://framework.zend.com/archives Unsubscribe: fw-general-unsubscr...@lists.zend.com