Is there some magic in Symfony/doctrine with a model called JosVmOrderHistory?
I have this schema.yml excerpt:
JosVmOrder:
tableName: jos_vm_orders
columns:
order_id: { type: integer(4), primary: true, autoincrement: true }
user_id: { type: integer(4), notnull: true }
vendor_id: { type: integer(4), notnull: true }
order_number: { type: string(32), notnull: false }
user_info_id: { type: string(32), notnull: false }
order_total: { type: 'decimal(15, 5)', notnull: true }
order_subtotal: { type: 'decimal(15, 5)', notnull: false }
order_tax: { type: 'decimal(10, 2)', notnull: false }
order_tax_details: { type: string(), notnull: true }
order_shipping: { type: 'decimal(10, 2)', notnull: false }
order_shipping_tax: { type: 'decimal(10, 2)', notnull: false }
coupon_discount: { type: 'decimal(12, 2)', notnull: true }
coupon_code: { type: string(32), notnull: false }
order_discount: { type: 'decimal(12, 2)', notnull: true }
order_currency: { type: string(16), notnull: false }
order_status: { type: string(1), notnull: false }
cdate: { type: integer(4), notnull: false }
mdate: { type: integer(4), notnull: false }
ship_method_id: { type: string(255), notnull: false }
customer_note: { type: string(), notnull: true }
ip_address: { type: string(15), notnull: true }
relations:
User: { class: JosUser, local: user_id, foreignAlias: OrderList }
LatestVmOrderDetail: { class: LatestVmOrderDetail, local: order_id, foreign: order_id }
JosVmOrderHistory:
tableName: jos_vm_order_history
columns:
order_status_history_id: { type: integer(4),primary: true, autoincrement: true }
order_id: { type: integer(4) }
order_status_code: { type: string(1) }
date_added: { type: timestamp(25) }
customer_notified: { type: integer(4), notnull: false }
comments: { type: clob(16777777), notnull: false }
relations:
Order: { class: JosVmOrder, local: order_id, foreign: order_id }
OrderStatus: { class: JosVmOrderStatus, local: order_status_code, foreign: order_status_code }
Firstly, the foreignAlias of JosVmOrderHistory is “JosVmOrderHistory”, not “JosVmOrderHistoryList” as I would have assumed.
Secondly, in model/doctrine/Order.class.php, I have the following function:
function getPaymentStatus(){
$historyList = $this->getJosVmOrderHistory();
if (count($historyList)){
return $paymentStatus = $historyList[0];
}else{
return $paymentStatus = null;
}
}
$historyList is always in descending order of order_status_history_id. I even added to model/doctrine/JosVmOrderHistoryTable.class.php:
public function createQuery($alias){
return parent::createQuery($alias)->orderBy('order_status_history_id asc');
}
but it stays in descending order..
Edit: I’ve updated the subject – this problem seems to come down to how to control the OrderBy of a relation query. createQuery doesn’t seem to be called at all.
If you need this for speed reasons you shouldnt load the entire order history from the DB if you are just interested in the first one, instead use a query like:
That being said, it is possible to automatically affect the sorting more like what you were trying to do by using a listener. In the past, I have created a generic sort behavior that you can use like: