我有以下SQL查询
SELECT *
FROM inventory_audits
WHERE id in (
SELECT distinct inventory_audits.id
FROM inventory_audits
LEFT JOIN pick_lists ON (pick_lists.number = substr(inventory_audits.reference,0,8))
LEFT JOIN pick_list_items ON (pick_list_items.pick_list_id = pick_lists.id)
LEFT JOIN load_plan_items ON (load_plan_items.load_plan_id = pick_list_items.load_plan_id)
LEFT JOIN sales_order_items ON (load_plan_items.sales_order_item_id = sales_order_items.id)
LEFT JOIN invoices ON (invoices.id = sales_order_items.invoice_id)
WHERE inventory_adjustment_reason_description = 'Picked'
AND (invoices.number = '230367' OR invoices.number = '230368')
)
并且,我需要将其转换为推进结果为
$cr = new Criteria();
$cr->addJoin(PickListPeer::ID, PickListItemPeer::PICK_LIST_ID);
$cr->addJoin(PickListItemPeer::LOAD_PLAN_ID, LoadPlanItemPeer::LOAD_PLAN_ID);
$cr->addJoin(LoadPlanItemPeer::SALES_ORDER_ITEM_ID, SalesOrderItemPeer::ID);
$cr->addJoin(SalesOrderItemPeer::INVOICE_ID, InvoicePeer::ID);
$cr->add(InventoryAuditPeer::INVENTORY_ADJUSTMENT_REASON_DESCRIPTION, 'Picked');
$cr->add(InvoicePeer::NUMBER, $invoiceNumbers, Criteria::IN);
$cr->setDistinct(true);
但我有点困惑,我怎么能在推进中转换这个联接...
LEFT JOIN pick_lists ON(pick_lists.number = SUBSTR(inventory_audits.reference,0,8))
,我试过这个但没有工作..
$ cr-> add(PickListPeer :: NUMBER,substr(InventoryAuditPeer :: REFERENCE, 0,8));
我正在使用推进1.2.1 任何引用都赞赏:) tyvm ..
答案 0 :(得分:0)
Nvm,我通过使用这条线来实现它。
$cr->addJoin('substr(inventory_audits.REFERENCE, 0, 8)', PickListPeer::NUMBER, Criteria::LEFT_JOIN);