【问题标题】:Condition to check existence of joined entity in Doctrine 2.1在 Doctrine 2.1 中检查是否存在联合实体的条件
【发布时间】:2014-02-09 22:24:57
【问题描述】:

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

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

这样:

Foo.bar > 1...0 > Bar

我想使用查询生成器或 DQL 选择所有 Foo 记录,其中

  1. Foo.value > :value

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

我该怎么做?

我正在使用这样的代码:

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

DQL 解决方案也足够了。

【问题讨论】:

    标签: php sql doctrine-orm


    【解决方案1】:

    我认为 IS NOT NULL 是你要找的。​​p>

    在 DQL 中:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-08-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多