#105387Add an exception for update or delete with join and queryBuilder
Description
With queryBuilder, you can make a delete or update query with a join condition like this:
$queryBuilder = $this->connectionPool->getQueryBuilderForTable('tt_content');
$queryBuilder
->update('tt_content')
->leftJoin('tt_content', 'sys_file_reference')
->where(
$queryBuilder->expr()->eq('tt_content.bodytext', $queryBuilder->createNamedParameter('lorem', Connection::PARAM_STR)),
$queryBuilder->expr()->eq('sys_file_reference.fieldname', $queryBuilder->createNamedParameter('assets', Connection::PARAM_STR)),
)
->set('tt_content.bodytext', 'dolor')
->executeStatement();
but join condition are not supported by doctrine/dbal because the join method is not supported in all db engines for delete or update.
And with queryBuilder this result in an SQL error like:
> (1/3) #1054 Doctrine\DBAL\Exception\InvalidFieldNameException
> An exception occurred while executing a query: Unknown column ‘sys_file_reference.fieldname’ in ‘where clause’
which is not very clear.
I suggest to add an exception in queryBuilder when you try to add a join for an update or a delete.
Reviews 4
- main 87585[TASK] Throw exception for QueryBuilder UPDATE/DELETE with table joins
- 12.4 87601[TASK] Avoid invalid reuse of QueryBuilder in Typo3DatabaseBackend
- 13.4 87600[TASK] Avoid invalid reuse of QueryBuilder in Typo3DatabaseBackend
- main 87586[TASK] Avoid invalid reuse of QueryBuilder in Typo3DatabaseBackend