Issue Bug Closed

#102298SQL JOIN in inherited SuggestWizardReceiver leeds to SQL Exception

Achim Fritz 10/31/23, 15:12 updated 07/09/24, 15:19

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)

Reviews 3

History 37

  1. Gerrit Code Review pushed patch set 1 for main to change 81637 status New Under Review 10/31/23, 15:20

  2. Gerrit Code Review pushed patch set 2 for main to change 81637 10/31/23, 18:22

  3. Anonymous commented and changed status Under Review Resolved done 0 % 100 % 11/02/23, 15:50

    Applied in changeset commit:5c3ad376875e1c1cfa81053e378968bb0fde3935.

  4. Gerrit Code Review pushed patch set 1 for 12.4 to change 81650 status Resolved Under Review 11/02/23, 15:53

  5. Gerrit Code Review pushed patch set 1 for 11.5 to change 81651 11/02/23, 15:57

  6. Anonymous commented and changed status Under Review Resolved 11/02/23, 16:30

    Applied in changeset commit:b5fe05c8edd1386d650825d1a7a616ef52a5512e.

  7. Benni Mack changed status Resolved Closed 07/09/24, 15:19