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;
}
};
Not exactly like yours but:
$select = new Sql\Select('foo');
$where = $select->where;
$where->NEST->like('givenName',"%Ralph%")
->OR->like('surname',"%Schindler%")
->UNNEST;
$where->AND->NEST->literal('active = 1')->UNNSET;
$select->order('surname ASC');
$select->offset(5);
$select->limit(10);
produces something *like*:
SELECT "foo".* FROM "foo" WHERE ("givenName" LIKE '%Ralph%' OR "surname"
LIKE '%Schindler%') AND (active = 1) ORDER BY "surname" ASC LIMIT '10'
OFFSET '5'
Anyone have insights?
Basically, you're talking about nested predicate sets:
simple example:
https://github.com/ralphschindler/Zend_Db-Examples/blob/master/example-13.php
Where the magic happens:
https://github.com/ralphschindler/zf2/blob/master/library/Zend/Db/Sql/Predicate/Predicate.php
Think of that class a class full of macros for doing the actual object
graphing.
Hope this helps,
Ralph
--
List: fw-general@lists.zend.com
Info: http://framework.zend.com/archives
Unsubscribe: fw-general-unsubscr...@lists.zend.com