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 #1

Updated by Gerrit Code Review over 9 years ago

  • Status changed from New to Under Review

Patch set 1 for branch TYPO3_6-1 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/33252

Actions #2

Updated by Gerrit Code Review over 9 years ago

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

Actions #3

Updated by Alexander Opitz almost 9 years ago

  • Status changed from Under Review to Closed

Closed in favor of patch from #27057

Actions

Also available in: Atom PDF