The xPDOQuery extends the xPDOCriteria class and allows you to abstract out complex SQL queries into an OOP format. This allows encapsulation of SQL calls so that they can work in multiple database types, and be easy to read and dynamically build.
Grab the first 4 Boxes with:
Owners that have the letter 'a' in their names
A width of at least 10
A height that is not 2
A color of 'red','blue' or 'green'
sorted by the Box name, ascending and then by the Box height, descending
$query = $xpdo->newQuery('Box');
// the Owner is actually a User object, defined as Owner in the relationship alias
'Owner.name:LIKE' => '%a%',
'Box.width:>=' => 10,
'Box.height:!=' => 2,
'Box.color:IN' => array('red','green','blue'),
$boxes = $xpdo->getCollection('Box',$query);
( `Person`.`first_name` = 'Bob'
OR ( `Person`.`last_name` LIKE 'Boblablaw' AND `Person`.`gender` = 'M' )
AND password IS NOT NULL
Note that if you're specifying the conditional in the key string, such as 'OR:disabled:!=' => true, you'll need to specify the operand as well. This means that you must specify = explicitly, such as in:
'AND:gender:=' => 'M'
$c = $xpdo->newQuery('Person');
'name:=' => 'John', /* Equal To */
'name:!=' => 'Sue', /* Unequal To */
'age:>' => '21', /* Greater Than */
'age:>=' => '21', /* Greater Than or Equal To */
'age:<' => '18', /* Less Than */
'age:<=' => '18', /* Less Than or Equal To */
'search:LIKE' => 'Term', /* LIKE statement */
'field' => null, /* check for NULL */
'ids:IN' => array(1,2,3), /* IN statement */
Sometimes you need to see what query is actually being generated. You can do this by preparing the query and outputting it using the toSQL() method.