学说不存在子查询 [英] doctrine not exists subquery

查看:85
本文介绍了学说不存在子查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在存储库中有以下代码:

I have in a repository this code:

 public function getNotAssignedBy($speciality, $diploma)
{
    $qb = $this->createQueryBuilder('j')
        ->select('DISTINCT(j.id) id', 'j.firstName', 'j.lastName', 'j.dateBirth', 'j.sex')
        ->leftJoin('j.qualifications', 'q')
    ;


    if ($speciality) {
        $qb->andWhere('q.speciality = :speciality_id')->setParameter('speciality_id', $speciality);
    }
    if ($diploma) {
        $qb->andWhere('q.diploma = :diploma_id')->setParameter('diploma_id', $diploma);
    }

    $result = $qb->getQuery()->getResult();

    return $result;
}

如何仅获取ID在另一个实体中不存在的行?

How can I get only rows where id not exists in another entity ??

任何帮助。谢谢

推荐答案

您可以通过以下方式实现它:

You can achieve it with something like this:

    ....
    // construct a subselect joined with an entity that have a relation with the first table as example user
    $sub = $this->createQueryBuilder();
    $sub->select("t");
    $sub->from("AnotherEntity","t");
    $sub->andWhere('t.user = j.id');

    // Your query builder:
    $qb->andWhere($qb->expr()->not($qb->expr()->exists($sub->getDQL())));

希望获得帮助

这篇关于学说不存在子查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆