Is it possible to inverse a 1:1 Relation without adding a second field into DB in Extbase?
Example: The extension has Contact-Persons which can have an fe_user. The Contact-Person-Domain-Model is the owning site of the relation.
Now you can use $contactPerson->getFrontendUser();
Is there any way to add an inversed property to FrontendUser without adding it to the DB?
So you can use $frontendUser->getContactPerson()
,
or even more important: $frontendUserRepository->findByContactPerson()
;
I tried adding the property to the FrontendUser-Model:
/**
* FrontendUser
*/
class FrontendUser extends \TYPO3\CMS\Extbase\Domain\Model\FrontendUser
{
/**
* @var \Vendor\ExtKey\Domain\Model\ContactPerson
*/
protected $contactPerson = null;
}
And overriding the fe_users TCA:
$GLOBALS['TCA']['fe_users']['columns']['contact_person'] = array(
'exclude' => 1,
'label' => 'LLL:EXT:ExtKey/Resources/Private/Language/locallang_db.xlf:tx_ExtKey_domain_model_contactperson',
'config' => array(
'type' => 'inline',
'foreign_table' => 'tx_ExtKey_domain_model_contactperson',
'foreign_field' => 'frontend_user',
'minitems' => 0,
'maxitems' => 1,
),
);
But when I call:
/**
* The repository for Customers
*/
class FrontendUserRepository extends \TYPO3\CMS\Extbase\Domain\Repository\FrontendUserRepository
{
/**
* @param \Vendor\ExtKey\Domain\Model\ContactPerson $contactPerson
* @param boolean $ignoreEnableFields
* @param boolean $respectStoragePage
* @return object
*/
public function findByContactPerson(ContactPerson $contactPerson, $ignoreEnableFields = false, $respectStoragePage = true){
$query = $this->createQuery();
$query->getQuerySettings()
->setIgnoreEnableFields($ignoreEnableFields)
->setRespectStoragePage($respectStoragePage);
$query->matching($query->equals('contactPerson', $contactPerson));
return $query->execute()->getFirst();
}
}
It creates following SQL-Error:
Unknown column 'fe_users.contact_person' in 'where clause'