MODX Cloud

The Most Productive MODX Learning Playground Ever

Claim Free Lab Account

xPDOQuery

Skip to end of metadata
Go to start of metadata


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:

  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

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.