Project

General

Profile

Actions

Bug #21710

closed

List modul doesn't sort m:m relation properly

Added by 4eyes GmbH almost 15 years ago. Updated almost 10 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
-
Target version:
-
Start date:
2009-11-27
Due date:
% Done:

0%

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

Description

If you use the list module to sort records according to their mm-relation you won't get any useful results.

My idea for a solution is adding the following code to class.db_list_extra.inc, after Line 409 (4.2.9)

if (isset($TCA[$table]['columns'][$queryParts['ORDERBY']]['config']['MM'])) {
$mmTable = $TCA[$table]['columns'][$queryParts['ORDERBY']]['config']['MM'];
$foreignTable = $TCA[$table]['columns'][$queryParts['ORDERBY']]['config']['foreign_table'];
$foreignTableLabelField = $TCA[$foreignTable]['ctrl']['label'];

$queryParts['SELECT'] = $table.'.'.str_replace(',',','.$table.'.',$queryParts['SELECT']);
$queryParts['SELECT'] .= ', GROUP_CONCAT('.$foreignTable.'.'.$foreignTableLabelField.') as tmp';
$queryParts['FROM'] .= ' LEFT JOIN '.$mmTable.' ON (uid_local = '.$table.'.uid)
LEFT JOIN '.$foreignTable.' ON (uid_foreign = '.$foreignTable.'.uid)';
$queryParts['ORDERBY'] = 'tmp';
$queryParts['GROUPBY'] = $table.'.uid';
$queryParts['WHERE'] = $table.'.'.$queryParts['WHERE'];
}

Of course is only a draft, there are several aspects not covered:
- hidden records in foreign table
- only one sorting direction
- group fields

Problem still exists in 4.3RC2
(issue imported from #M12789)

Actions

Also available in: Atom PDF