When using $mod->newQuery(); and joining a table, how can I get the data returned to include the fields from the joined table?
Right now, I have to run the query, then based on the results, run getObject() to retrieve an object that was already used in the join. Is it possible to grab it all with one swoop?
The query is searching for customers based on orders imported. Thre tables, OrderImports, Skus, and Products. I don;t think the details of the data is too relevant for this question, but if it helps please let me know.
Example: Searching for a Customer LIKE 'Mike%' in $queryArray. I get the correct results, so the query works. I just want to avoid the extra step ***
This is my current query:
//BuIld Query to search customers
$query = $modx->newQuery('OrderImports');
$query->leftJoin('Skus', 'Skus', array(
'OrderImports.aps_id' => 'Skus.aps_id',
));
$query->where($queryArray);
$query->limit(50);
//Search customers
$customers = $modx->getCollection('OrderImports',$query);
if($customers){
//lopp thorugh each customer
foreach($customers as $customer){
//find the product id of the SKU relationship
//***(trying to skip step step below since skus is already used in join)
$prodSkus = $modx->getObject('Skus',array('aps_id'=>$customer->get('aps_id')));
if(!$prodSkus){
//if SKU is not found, go to next customer
continue;
}
//**trying to skip step above
//grab the product based on product ID
$prodObj = $modx->getObject('Products',array('ap_id' => $prodSkus->get('ap_id')));
if($prodObj){
//do stuff with customer and product object and return output to user
}else{
//move on to next
continue;
}
}
}
Using MySQL, Php 5.5, Apache