Project

General

Profile

Actions

Bug #62151

closed

addUnionStatement does not handle multiple fields with same related table

Added by Nils Heuermann over 9 years ago. Updated almost 9 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
Extbase
Target version:
-
Start date:
2014-10-10
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
6.1
PHP Version:
Tags:
Complexity:
Is Regression:
No
Sprint Focus:

Description

When a domain model has more than 1 field which are related to the same table you cannot create a query checking both fields.

Example:
Domain\Model\ContentDraft (content_draft)
- creator: Domain\Model\FrontendUser (fe_users)
- editor: Domain\Model\FrontendUser (fe_users)

To search for drafts for a user name, a query may be created like this in Domain\Repository\ContentDraft:

$query = $this->createQuery() ;

$constraints = array() ;
$constraints[] = $query->like('creator.name', 'name1') ;
$constraints[] = $query->like('editor.name', 'name2') ;

$query->matching(
    $query->logicalOr($constraints)
) ;

When the query is build in Typo3DbBackend there's only one JOIN clause for fe_users and two WHERE conditions which target the same (joined) table. Simplified query:

SELECT * FROM content_draft.* LEFT JOIN fe_users ON content_draft.editor=fe_users.uid WHERE fe_users.name LIKE '%name1%' OR fe_users.name LIKE '%name2%'

Though it should be something like this:
SELECT * FROM content_draft.* LEFT JOIN fe_users AS fe_users1 ON content_draft.creator=fe_users.uid LEFT JOIN fe_users AS fe_users2 ON content_draft.editor=fe_users.uid WHERE fe_users1.name LIKE '%name1%' OR fe_users2.name LIKE '%name2%'

In Typo3DbBackend::addUnionStatement() the join clauses are added to $sql['unions'] but every time $childTableName is used as key, so only the join clause for the last constraint is saved in the array and eventually added to the query. Also the where conditions do all use fe_users and do not differntiate for the multiple constraints.


Related issues 1 (0 open1 closed)

Related to TYPO3 Core - Bug #27057: Can't query on properties of child objects of the same classClosedAlexander Schnitzler2011-05-26

Actions
Actions

Also available in: Atom PDF