Project

General

Profile

Actions

Bug #81490

closed

Missing DISTINCT when building query with left joins in extbase repository

Added by Michael Stopp almost 7 years ago. Updated over 6 years ago.

Status:
Closed
Priority:
Must have
Assignee:
-
Category:
Extbase
Target version:
-
Start date:
2017-06-06
Due date:
% Done:

0%

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

Description

While migrating an extbase extension from 6.2 to 8.7 I noticed that a custom repository query returned duplicate result rows in T3 V8.7.
In simple terms, the model hierarchy in this example is: a competition can have one or more editions and an edition can have one or more submissionslots.
The task is to retrieve all competitions with at least one valid submission slot (i.e. deadline must not be smaller than defined start date).
The deadline check in the competition repository is done with:

$query->greaterThanOrEqual('editions.submissionSlots.deadline', $start->format('Y-m-d'));

In T3 V6.2 this resulted in the following SQL statement (simplified for readability):

SELECT DISTINCT tx_myext_competition.* 
FROM tx_myext_competition 
LEFT JOIN tx_myext_edition ON tx_myext_competition.uid=tx_myext_edition.competition 
LEFT JOIN tx_myext_submissionslot ON tx_myext_edition.uid=tx_myext_submissionslot.edition 
WHERE tx_myext_submissionslot.deadline >= '2017-06-06' [...]

In T3 V8.7 the same query results in:

SELECT tx_myext_competition.* 
FROM tx_myext_competition tx_myext_competition 
LEFT JOIN tx_myext_edition tx_myext_edition ON tx_myext_competition.uid = tx_myext_edition.competition 
LEFT JOIN tx_myext_submissionslot tx_myext_submissionslot ON tx_myext_edition.uid = tx_myext_submissionslot.edition
WHERE tx_myext_submissionslot.deadline >= '2017-06-06' [...]

The crucial difference is the missing DISTINCT, which results in duplicate rows in the result set as a competition can have multiple valid submission slots.
(The table name aliases are also a bit weird, but do no harm...)


Related issues 1 (0 open1 closed)

Related to TYPO3 Core - Feature #80380: Missing Distinct / GroupBy option in QueryClosed2017-03-21

Actions
Actions

Also available in: Atom PDF