Bug #62151
closedaddUnionStatement does not handle multiple fields with same related table
0%
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.
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
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
Updated by Alexander Opitz almost 9 years ago
- Status changed from Under Review to Closed
Closed in favor of patch from #27057