我正在尝试使用doctrine
从mysql中删除记录对应的MYSQL查询
DELETE FROM user_fields_data WHERE id NOT IN (
SELECT * FROM (
SELECT id FROM user_fields_data WHERE id IN (
SELECT block_id FROM user_fields_data WHERE template = 1
)
) AS `ss`
) AND template = 1
尝试使用Doctrine删除:
$qb = $this->_em->createQueryBuilder();
$blockId = $qb->select('bl.blockId')
->from('UserFieldBundle:UserFieldsData','bl')
->where('bl.template = 1');
$ids = $qb->select('bl2.id')
->from('UserFieldBundle:UserFieldsData','bl2')
->where($qb->expr()->in('bl2.id',$blockId->getDQL()));
$result = $qb->delete('UserFieldBundle:UserFieldsData','USF')
->where($qb->expr()->notin('USF.id', $ids->getDQL()))
->andWhere('USF.template = :templateId')
->setParameter('templateId', 1)
->getQuery()
->getSQL();
dump($result);
Doctrine查询以错误结束:
[语法错误]第0行,第65行:错误:预期文字,得到'删除'“
数据库结构: