Bug #87411

Multiple conditions for QueryBuilder leftJoin not possible

Added by Stefan Froemken 2 months ago. Updated 2 months ago.

Status:
Resolved
Priority:
Should have
Category:
Database API (Doctrine DBAL)
Target version:
Start date:
2019-01-11
Due date:
% Done:

100%

TYPO3 Version:
8
PHP Version:
7.1
Tags:
Complexity:
easy
Is Regression:
Sprint Focus:

Description

Hello Core-Team,

in case of joining f.e. sys_category I have to do generate following SQL

LEFT JOIN sys_category_record_mm
ON tx_events2_domain_model_event.uid = sys_category_record_mm.uid_foreign
AND sys_category_record_mm.tablenames = 'tx_events2_domain_model_event'
AND sys_category_record_mm.fieldname = 'categories'

I tried to solve it like described here:
https://stackoverflow.com/questions/15815869/doctrine2-left-join-with-2-conditions

$queryBuilder->leftJoin(
    'e',
    'sys_category_record_mm',
    'cmm',
    $queryBuilder->expr()->andX(
        $queryBuilder->expr()->eq(
            'e.uid',
            $queryBuilder->quoteIdentifier('cmm.uid_foreign')
        ),
        $queryBuilder->expr()->eq(
            'cmm.tablenames',
            $queryBuilder->createNamedParameter('tx_events2_domain_model_event', \PDO::PARAM_STR)
        ),
        $queryBuilder->expr()->eq(
            'cmm.fieldname',
            $queryBuilder->createNamedParameter('categories', \PDO::PARAM_STR)
        )
    )
);

But that results in an error message like "CompositeExpression given but string expected."

Right. You have strict typed 4th parameter in leftJoin:

public function leftJoin(string $fromAlias, string $join, string $alias, string $condition = null): QueryBuilder

Is it a problem to remove that strict type?

Stefan

History

#1 Updated by Gerrit Code Review 2 months ago

  • Status changed from New to Under Review

Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/59412

#2 Updated by Gerrit Code Review 2 months ago

Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/59412

#3 Updated by Stefan Froemken 2 months ago

  • Status changed from Under Review to Resolved
  • Assignee set to Stefan Froemken
  • % Done changed from 0 to 100

Ticket can be closed. Use getConcreteQueryBuilder()->leftJoin() or cast ExpressionBuilder to string.

Also available in: Atom PDF