[BUGFIX] Fix database query in StaticRecordCollection 32/53132/3
authorTymoteusz Motylewski <t.motylewski@gmail.com>
Sat, 8 Jul 2017 17:44:10 +0000 (19:44 +0200)
committerTymoteusz Motylewski <t.motylewski@gmail.com>
Fri, 14 Jul 2017 07:14:41 +0000 (09:14 +0200)
Fix the query to fetch collection records to use an alias for the
foreign table instead of the MM tables and properly join on uid_local
and uid_foreign.

Change-Id: Idf9bacd84f4a2980470183ede034e7edaa489a3f
Resolves: #81353
Releases: master, 8.7
Reviewed-on: https://review.typo3.org/53132
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Tymoteusz Motylewski <t.motylewski@gmail.com>
Tested-by: Tymoteusz Motylewski <t.motylewski@gmail.com>
typo3/sysext/core/Classes/Collection/StaticRecordCollection.php

index cf82613..aa2fc8c 100644 (file)
@@ -158,26 +158,27 @@ class StaticRecordCollection extends AbstractRecordCollection implements Editabl
      */
     protected function getCollectedRecords()
     {
-        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable(self::$storageTableName);
+        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
+            ->getQueryBuilderForTable(self::$storageTableName);
         $queryBuilder->getRestrictions()->removeAll();
         $statement = $queryBuilder->select($this->getItemTableName() . '.*')
             ->from(self::$storageTableName)
             ->join(
                 self::$storageTableName,
                 'sys_collection_entries',
-                'sys_collection_entries_join',
+                'sys_collection_entries',
                 $queryBuilder->expr()->eq(
-                    'sys_collection_entries_join.uid_local',
+                    'sys_collection_entries.uid_local',
                     $queryBuilder->quoteIdentifier(self::$storageTableName . '.uid')
                 )
             )
             ->join(
-                'sys_collection_entries_join',
+                'sys_collection_entries',
+                $this->getItemTableName(),
                 $this->getItemTableName(),
-                $this->getItemTableName() . '_join',
                 $queryBuilder->expr()->eq(
-                    'sys_collection_entries_join.uid_local',
-                    $queryBuilder->quoteIdentifier($this->getItemTableName() . '_join.uid')
+                    'sys_collection_entries.uid_foreign',
+                    $queryBuilder->quoteIdentifier($this->getItemTableName() . '.uid')
                 )
             )
             ->where(