Skip to content

Commit

Permalink
🐛 fix sorting of MM relations
Browse files Browse the repository at this point in the history
  • Loading branch information
Kanti authored Feb 8, 2024
1 parent a7122da commit f7b6198
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions Classes/DataProcessing/RelationProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,28 +146,26 @@ private function getRowsMM(mixed $tcaConfig, mixed $foreignTable, int $uid): arr
$mmTable = $tcaConfig['MM'] ?? throw new RuntimeException('TCA config MM not found');

$matchFields = $tcaConfig['MM_match_fields'] ?? [];
$sorting = $tcaConfig['mm_sorting_field'] ?? '';

$otherWay = isset($tcaConfig['MM_opposite_field']);

if ($otherWay) {
$selfField = 'uid_foreign';
$otherField = 'uid_local';
$sorting = 'sorting_foreign';
} else {
$selfField = 'uid_local';
$otherField = 'uid_foreign';
$sorting = 'sorting';
}

$queryBuilder = $this->connectionPool->getQueryBuilderForTable($foreignTable);
$queryBuilder
->select('relation.*')
->from($foreignTable, 'relation')
->join('relation', $mmTable, 'mm', $queryBuilder->expr()->eq('relation.uid', 'mm.' . $otherField))
->where($queryBuilder->expr()->eq('mm.' . $selfField, $uid));

if ($sorting) {
$queryBuilder->orderBy($sorting);
}
->where($queryBuilder->expr()->eq('mm.' . $selfField, $uid))
->orderBy('mm.' . $sorting);

$transOrigPointerField = $GLOBALS['TCA'][$foreignTable]['ctrl']['transOrigPointerField'] ?? null;
if ($transOrigPointerField) {
Expand Down

0 comments on commit f7b6198

Please sign in to comment.