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.
Examples
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
- sorted by the Box name, ascending and then by the Box height, descending
$query = $xpdo->newQuery('Box');
$query->innerJoin('Owner','User');
// the Owner is actually a User object, defined as Owner in the relationship alias
$query->where(array(
'Owner.name:LIKE' => '%a%',
'Box.width:>=' => 10,
'Box.height:!=' => 2,
));
$query->sortby('Box.name','ASC');
$query->sortby('Box.height','DESC');
$query->limit(4);
$boxes = $xpdo->getCollection('Box',$query);
See Also
Labels
Page:
xPDOQuery.andCondition
Page: xPDOQuery.groupby
Page: xPDOQuery.innerJoin
Page: xPDOQuery.leftJoin
Page: xPDOQuery.limit
Page: xPDOQuery.orCondition
Page: xPDOQuery.rightJoin
Page: xPDOQuery.select
Page: xPDOQuery.setClassAlias
Page: xPDOQuery.sortby
Page: xPDOQuery.where
Page: xPDOQuery.groupby
Page: xPDOQuery.innerJoin
Page: xPDOQuery.leftJoin
Page: xPDOQuery.limit
Page: xPDOQuery.orCondition
Page: xPDOQuery.rightJoin
Page: xPDOQuery.select
Page: xPDOQuery.setClassAlias
Page: xPDOQuery.sortby
Page: xPDOQuery.where