xPDOQuery

Welcome to the MODX Documentation. It is an ongoing effort of the MODX community. If you would like to participate or if you notice any errors or missing content, please let us know.

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.

  1. xPDOQuery.andCondition
  2. xPDOQuery.groupby
  3. xPDOQuery.innerJoin
  4. xPDOQuery.leftJoin
  5. xPDOQuery.limit
  6. xPDOQuery.orCondition
  7. xPDOQuery.rightJoin
  8. xPDOQuery.select
  9. xPDOQuery.setClassAlias
  10. xPDOQuery.sortby
  11. xPDOQuery.where

Examples

Grab the first 4 Boxes with:

  1. Owners that have the letter 'a' in their names
  2. A width of at least 10
  3. A height that is not 2
  4. 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