美文网首页
不能跨越两条车道并线的 doctrine join

不能跨越两条车道并线的 doctrine join

作者: forks1990 | 来源:发表于2020-05-30 22:48 被阅读0次

    假设有四张表,合同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
    

    相关文章

      网友评论

          本文标题:不能跨越两条车道并线的 doctrine join

          本文链接:https://www.haomeiwen.com/subject/texkzhtx.html