How to join multiple entities on a foreign ID in Symfony 4 using a query builder?

后端 未结 3 942
一整个雨季
一整个雨季 2021-01-21 09:07

I\'m trying to learn Symfony. Today I was following The associations tutorial. I decided to make a small application that a House, Kitchens, Bedrooms, and cabinets. I (tried to

3条回答
  •  礼貌的吻别
    2021-01-21 09:38

    First I think because you joining with both entities at the same time in this

    ...
                ->join('cabinet.bedroom', 'bedroom')
                ->join('cabinet.kitchen', 'kitchen')
    ...
    

    and because that will be with INNER JOIN, it will require that cabined is required both bedroom and kitchen cabinet.

    For that there is few solutions to work through:

    • Proper one would be redesign you entities. I think it might not be hard to use Doctrine inheritance
    • you might change joins to left, so relation is not mandatory (will work, but in general its not good solution because of wrong design)

提交回复
热议问题