Doctrine 2 DQL - Select rows where a many-to-many field is empty?

后端 未结 4 732
北恋
北恋 2020-12-15 05:23

I have two classes in this example - DeliveryMethod and Country. They have a many-to-many relationship with each other.

What I want to do is select all DeliveryMetho

4条回答
  •  一个人的身影
    2020-12-15 05:40

    There is no need in joins and havings. Simply use SIZE function:

    $qb->select('m')
       ->from('DeliveryMethods','m')
       ->where('SIZE(m.countries) = 0');
    

    This will give you all methods without attached countries

提交回复
热议问题