我 mysql 查询:
SELECT p.name, c.id
FROM customer c
INNER JOIN sales_order so ON so.customer_id=c.id
INNER JOIN sales_order_item soi ON so.id=soi.sales_order_id
INNER JOIN product p ON p.id=soi.product_id WHERE c.id=49454\G;
这在 MySql 中工作,但是当这个查询在学说 2 中转换时,它会给出错误
"[Semantical Error] line 0, col 87 near 'so ON so.customer_id=c.id': Error: Identification Variable sales_order used in join path expression but was not defined before."
在 symfony 中,我这样写:
$builder
->add('filter', 'entity', array(
'label' => 'Show',
'class' => 'RocketBraPrintBundle:SalesOrderItem',
'query_builder' => function($er) {
return $er->createQueryBuilder('p','so','c','soi')
->select('p.name','c.id')
->from('customer','c')
->innerJoin('sales_order','so','ON','so.customer_id=c.id')
->innerJoin('sales_order_item','soi','ON','so.id=soi.sales_order_id')
->innerJoin('product','p', 'ON', 'p.id=soi.product_id')
->where('c.id=49454\G');
},
'empty_value' => 'All',
'required' => false
))
谁能告诉我以 symfony2 方式转换这个 mysql 查询的正确方法是什么?