Project

General

Profile

Actions

Bug #102298

closed

SQL JOIN in inherited SuggestWizardReceiver leeds to SQL Exception

Added by Achim Fritz 6 months ago. Updated 6 months ago.

Status:
Resolved
Priority:
Should have
Assignee:
-
Category:
Backend API
Target version:
-
Start date:
2023-10-31
Due date:
% Done:

100%

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

Description

the "SuggestWizardDefaultReceiver" is inteded to be inherited from other Implementation of Ajax Suggest Receiver (s. https://github.com/TYPO3/typo3/blob/main/typo3/sysext/backend/Classes/Form/Wizard/SuggestWizardDefaultReceiver.php#L33)

if we extend it and add a JOIN to an other table it leeds to an SQL Exception


(1/3) Doctrine\DBAL\Exception\NonUniqueFieldNameException

An exception occurred while executing 'SELECT COUNT(`uid`) FROM `mmn_person_function_unit` INNER JOIN `domain_model_person` `person` ON `person`.`uid` = mmn_person_function_unit.person_uid WHERE (`mmn_person_function_unit`.`foreign_uid` = ?) AND (`person`.`sortingname` LIKE ? ESCAPE '\\') AND (`person`.`sys_language_uid` LIKE ? ESCAPE '\\') AND (`person`.`deleted` = 0) LIMIT 50' with params [1809, "%karl%", 0]: Column 'uid' in field list is ambiguous


class MyRelationReceiver extends SuggestWizardDefaultReceiver

    protected function prepareSelectStatement()
    {
        $expressionBuilder = $this->queryBuilder->expr();

        $this->queryBuilder->resetQueryParts();

        $this->queryBuilder
            ->join(
                $this->table,
                'domain_model_person',
                'person',
                $expressionBuilder->eq('person.uid', $this->table . '.person_uid')
            )
            ->where(
                $expressionBuilder->eq($this->table . '.foreign_uid', $this->queryBuilder->createNamedParameter((int)$this->params['uid'], \PDO::PARAM_INT)),
                $expressionBuilder->like('person.sortingname', $this->queryBuilder->createNamedParameter('%' . $this->params['value'] . '%'))
            );
    }

and TCA

        '<my-field>' => [
            'label' => 'My Relation',
            'config' => [
                'type' => 'group',
                'allowed' => 'mmn_person_function_unit',
                'foreign_table' => 'mmn_person_function_unit',
                'suggestOptions' => [
                    'default' => [
                        'receiverClass' => <MyRelationReceiver>,
                    ],
                ],
            ],
        ],

the "select()" and "count()" in the "queryTable" Method should prefix fields with "table"

this affects all TYPO3 Versions (11,12,13)

Actions #1

Updated by Gerrit Code Review 6 months ago

  • Status changed from New to Under Review

Patch set 1 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/81637

Actions #2

Updated by Gerrit Code Review 6 months ago

Patch set 2 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/81637

Actions #3

Updated by Anonymous 6 months ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100
Actions #4

Updated by Gerrit Code Review 6 months ago

  • Status changed from Resolved to Under Review

Patch set 1 for branch 12.4 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/81650

Actions #5

Updated by Gerrit Code Review 6 months ago

Patch set 1 for branch 11.5 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/81651

Actions #6

Updated by Anonymous 6 months ago

  • Status changed from Under Review to Resolved
Actions

Also available in: Atom PDF