假设有四张表,合同contract
,订单order
,产品明细orderItem
, 产品档案product
,以显而易见的方式关联在一起:
contract:
+ id
+ customer
+ orders // onetomany to order
order:
+ id
+ contract // manytoone to contract
+ items // onetomany to orderItem
orderItem:
+ id
+ order // manytoone to order
+ product // manytoone to product
product:
+ id
+ name
查询customer
和他所购买的产品:
select a.customer, p.name
from App\Entity\Contract a
join a.order.orderItem.product p
join a.order.orderItem.product p
是不对的,只能join一次,需要修改成:
select a.customer, p.name
from App\Entity\Contract a
join a.order o
join o.items it
join it.product p
网友评论