Project

General

Profile

Actions

Bug #87411

closed

Multiple conditions for QueryBuilder leftJoin not possible

Added by Stefan Froemken almost 6 years ago. Updated over 5 years ago.

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

100%

Estimated time:
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

Actions

Also available in: Atom PDF