I’m using xPDO to perform a SELECT query that generates a couple of “synthetic” columns (i.e. fields calculated dynamically by the query). This works fine, except when it comes to referring to these columns in a WHERE or HAVING clause.
Here’s an example:
$q = $modx->newQuery('Show');
$q->innerJoin('ShowDate', 'ShowDate');
$q->select();
$q->select(array(
'startDate' => 'MIN(ShowDate.moment)',
'endDate' => 'MAX(ShowDate.moment)',
));
$q->groupby('Show.id');
$q->having(array(
// starts over 1 week from now
'startDate:>=' => date('Y-m-d 00:00:00', time() + 604800)
));
$q->sortby('startDate');
$shows = $modx->getCollection('Show', $q);
See the call to having? That causes an error, as xPDO converts the unqualified column name startDate to `Show`.`startDate`, which doesn’t exist.
How do I tell xPDO that the startDate column I’m referring to doesn’t belong to a particular table in my query, and therefore doesn’t need to be qualified with a table name?