Bug #21710
closedList modul doesn't sort m:m relation properly
0%
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)