gpt4 book ai didi

php - 学说不存在子查询

转载 作者:可可西里 更新时间:2023-11-01 12:26:59 24 4
gpt4 key购买 nike

我在存储库中有这段代码:

 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 的行??

任何帮助。谢谢

最佳答案

你可以用这样的东西来实现它:

    ....
// 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())));

希望对你有帮助

关于php - 学说不存在子查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31536137/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com