Search code examples
extbasetypo3-extensions

Typo3 Error: The ColumnMap for property is missing (m:n)


I am having the same issue that was posted here:

Typo3 Error: The ColumnMap for property is missing

...except I am using a m:n relational table. Unfortunately my error continues:

I'm using Typo3 version 8.7.19 and I'm developing an extention. The two tables "mitarbeiter" and "zusatzlich" are connectet with a m:n relation. I try to search for a field in the table "zusatzlich" in the repository of "mitarbeiter". The relation of both is necessary.

If I try to execute the following query I get the error "The ColumnMap for property "tx_khsjmitarbeiter_domain_model_zusatzlich" of class "...\Mitarbeiter" is missing."

    $query =  $this->createQuery();

    $zu = [];

    if($zusatz1 != ""){
        $zu[] = $query->equals('tx_khsjmitarbeiter_domain_model_zusatzlich.zusatz', $zusatz1);
    }

    if(count($zu)>0){
        $query->matching($query->logicalAnd( $zu ));
    }

    return $query->execute();

The relevant TCA code of the field "connection_id" in "mitarbeiter" which contains the UID of "zusatzlich":

'connection_id' => [
        'exclude' => true,
        'label' => 'LLL:EXT:khsj_mitarbeiter/Resources/Private/Language/locallang_db.xlf:tx_khsjmitarbeiter_domain_model_mitarbeiter.connection_id',
        'config' => [
            'type' => 'select',
            'renderType' => 'selectCheckBox',
            'foreign_table' => 'tx_khsjmitarbeiter_domain_model_zusatzlich',
            'MM' => 'tx_khsjmitarbeiter_mitarbeiter_zusatzlich_mm',
        ],

    ],

This is the object model:

/**
 * connectionId
 *
 * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\..\Model\Zusatzlich>
 * @cascade remove
 */
protected $connectionId = null;


/**
 * Initializes all ObjectStorage properties
 * Do not modify this method!
 * It will be rewritten on each save in the extension builder
 * You may modify the constructor of this class instead
 *
 * @return void
 */
protected function initStorageObjects()
{
    $this->connectionId = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
}

/** * Adds a Zusatzlich * * @param ..\Model\Zusatzlich $connectionId * @return void */ public function addConnectionId(..\Model\Zusatzlich $connectionId) { $this->connectionId->attach($connectionId); }

/**
 * Removes a Zusatzlich
 *
 * @param \..\Model\Zusatzlich $connectionIdToRemove The Zusatzlich to be removed
 * @return void
 */
public function removeConnectionId(\..\Model\Zusatzlich $connectionIdToRemove)
{
    $this->connectionId->detach($connectionIdToRemove);
}

/**
 * Returns the connectionId
 *
 * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\..\Model\Zusatzlich> connectionId
 */
public function getConnectionId()
{
    return $this->connectionId;
}

/**
 * Sets the connectionId
 *
 * @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\..\Model\Zusatzlich> $connectionId
 * @return void
 */
public function setConnectionId(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $connectionId)
{
    $this->connectionId = $connectionId;
}

I can add and apply new zusatz items in the BE to any mitarbeiter item so I am confident it is set up properly in that respect. However I also noticed that if I change this line:

$zu[] = $query->equals('tx_khsjmitarbeiter_domain_model_zusatzlich.zusatz', $zusatz1);

...to this...

$zu[] = $query->equals('ANYTHINGATALL.zusatz', $zusatz1);

I get the same error referencing ANYTHINGATALL instead of tx_khsjmitarbeiter_domain_model_zusatzlich

Can anybody point me in the right direction?


Solution

  • j4k3’s answer led me to the right direction but is missing the property of the related model “zusatzlich”. Thus it should be:

    if ($zusatz1 != "") {
        $zu[] = $query->contains('connection_id.zusatz', $zusatz1);
    }
    

    It will be transformed into an SQL LeftJoin with the correct table names, given your relations are properly defined in the TCA.

    In case of a property with underscore (e.g. zusatz_xy), the lowerCamelCase version will also work (zusatzXy).