Left join alias missing on delete query #10935
-
Hello all, I'm trying to delete a record, and as a failsafe, I want to make sure at deletion time other tables do not have any reference. So my initial idea was to public function delete(int $myId): mixed
{
return $this->createQueryBuilder('firstTable')
->delete(FirstTable::class, 'firstTable')
->leftJoin(SecondTable::class, 'secondTable', Join::WITH, 'firstTable.id = secondTable.myId')
->where('firstTable.id = :myId')
->andWhere('secondTable.id is null')
->setParameter('myId', $myId, ParameterType::INTEGER)
->getQuery()
->getResult();
} The problem is that the alias of the join does not seem to be taken into consideration, I'm having the following error: Is this the expected behavior? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Yes. There is no JOIN in DELETE queries. Furthermore you're reinventing foreign key constraints. You should not need this "failsafe" code of yours. |
Beta Was this translation helpful? Give feedback.
Yes. There is no JOIN in DELETE queries.
Furthermore you're reinventing foreign key constraints. You should not need this "failsafe" code of yours.