Hello all,
Trust all are doing as best as they can during this covid-19 period. I’m trying to write a query with xPDO. The correct query syntax is: “SELECT Order
.user_id
, Order
.createdon
, OrderProduct
.product_id
FROM modx_ms2_orders
AS Order
LEFT JOIN modx_ms2_order_products
OrderProduct
ON OrderProduct
.order_id
= Order
.id
WHERE Order
.id
= 1”
This is the code that I wrote:
$query = $modx->newQuery(‘msOrder’);
$query->select($modx->getSelectColumns(‘msOrder’, ‘Order’,’’,array(‘user_id’,‘createdon’)));
$query->select($modx->getSelectColumns(‘msOrderProduct’, ‘OrderProduct’,’’,array(‘product_id’)));
$query->setClassAlias(‘Order’);
$query->leftJoin(‘msOrderProduct’,‘OrderProduct’,array(
‘OrderProduct.order_id:=’ => ‘Order.id’
));
$query->where(array(
‘Order.id’ => 1,
));
But when I try $orders = $modx->getCollection(‘msOrder’,$query), I’m getting a 500 error and the prepare -> toSQL return: “SELECT Order
.user_id
, Order
.createdon
, OrderProduct
.product_id
FROM modx_ms2_orders
AS Order
LEFT JOIN modx_ms2_order_products
OrderProduct
ON OrderProduct
.order_id
= ‘Order.id’ WHERE Order
.id
= 1”.
What should I do to make the SQL to return “OrderProduct
.order_id
= Order
.id
” instead of “OrderProduct
.order_id
= ‘Order`.id’”?