在Doctrine 2.1中检查连接实体是否存在的条件

时间:2014-02-09 22:24:58

标签: php sql doctrine-orm

我在Doctine 2.1中有两个具有OneToOne双向关系的实体。

Foo              |   Bar
--------------   |   --------------
id:    integer   |   id:    integer
value: integer   |   value: boolean
bar:   Bar       |   foo:   Foo

那样:

Foo.bar > 1...0 > Bar

我想使用Query Builder或DQL选择所有Foo记录

  1. Foo.value > :value

  2. Foo.bar不为空,即此Bar实体有Foo个实体

  3. 我该怎么做?

    我正在使用这样的代码:

    $builder
        ->select('F')
        ->from('Foo', 'F')
        ->where('F.value > :value')
        ->orWhere('F.bar ???')
    ;
    

    DQL解决方案也足够了。

1 个答案:

答案 0 :(得分:0)

我认为 IS NOT NULL 正是您所寻找的。

在DQL中:

$em->createQuery('SELECT f FROM Foo f WHERE F.value > :value OR F.bar IS NOT NULL');