1 回答
TA贡献1827条经验 获得超9个赞
使用mysql,它可以用这个查询
SELECT
gift.*, tag.*
FROM
gift
LEFT JOIN tag ON gift.id = tag.gift_id
WHERE gift.id NOT IN (
SELECT g.id FROM gift AS g LEFT JOIN tag AS t ON g.id = t.gift_id WHERE t.name IN ('test', 'test2')
)
所以根据 QB 学说,它可能是这样的
$subQb = $this->_em->createQueryBuilder()
->select('gift.id')
->leftJoin('gift.tags', 'tags')
->where($qb->expr()->orX(
$qb->expr()->in("tags.name", ":avoidTags")),
))
->getQuery();
$response = $qb
->select('g, tags')
->leftJoin('g.tags', 't')
->where($qb->expr()->notin("g.id", $subQb->getDql())))
->setParameters(new ArrayCollection([
new Parameter('avoidTags', $avoidTags),
]))
->getQuery()
->getResult();
- 1 回答
- 0 关注
- 127 浏览
添加回答
举报