Having some difficulty trying to find the correct syntax to join multiple related tables in an xPDO query:
$mygroups = $this->getGroupMemberships();
$criteria = $this->modx->newQuery('Contract');
$criteria->leftJoin('Client','Client');
$criteria->leftJoin('Program','Program');
$criteria->leftJoin('Location','Location', array('Program.location_id:=' => 'Location.id'));
$criteria->where(array('Contract.status_id' => 2,'OR:Contract.status_id:=' => 3));
$criteria->where(array('Client.first_name:LIKE' => "%$searchQuery%",'OR:Client.cams:LIKE' => "%$searchQuery%",'OR:Client.last_name:LIKE' => "%$searchQuery%"));
$criteria->where(array('Location.location_id:IN' => $mygroups));
$options = $this->modx->getCollectionGraph('Contract', '{ "Client": {}, "Program": { "ProgramName": {}, "Location": {}, }, }', $criteria);
$criteria->prepare();
$this->modx->log(modX::LOG_LEVEL_ERROR,'Running "getJsonPayees", sql = '.$criteria->toSQL());
But when I view the query it gives me:
SELECT (a whole lot of fields!)
FROM `flow_contract` AS `Contract`
LEFT JOIN `flow_client` `Client` ON `Contract`.`client_id` = `Client`.`id`
LEFT JOIN `flow_program` `Program` ON `Contract`.`program_id` = `Program`.`id`
LEFT JOIN `flow_location` `Location` ON `Program`.`location_id` = 'Location.id'
WHERE ( ( `Contract`.`status_id` = 2 OR `Contract`.`status_id` = 3 )
AND ( `Client`.`first_name` LIKE '%k%' OR `Client`.`cams` LIKE '%k%' OR `Client`.`last_name` LIKE '%k%' ) AND `Location`.`id` IN (1,2,3,4,5,6,7,8,9,10) )
If I change:
LEFT JOIN `flow_location` `Location` ON `Program`.`location_id` = 'Location.id'
To
LEFT JOIN `flow_location` `Location` ON `Program`.`location_id` = `Location`.`id`
Then it works perfectly ... what is the correct syntax to make that happen?