在Extbase中,是否可以在不向DB中添加第二个字段的情况下逆1:1关系?
例如:扩展有联系人-人员,可以有一个fe_user。联系人-人-域-模型是关系的所有者站点.
现在您可以使用$contactPerson->getFrontendUser();
了
有没有办法在不将其添加到DB的情况下向FrontendUser添加反向属性?
所以你可以使用$frontendUser->getContactPerson()
,
或者更重要的是:$frontendUserRepository->findByContactPerson()
;
我尝试将该属性添加到FrontendUser Model中:
/**
* FrontendUser
*/
class FrontendUser extends \TYPO3\CMS\Extbase\Domain\Model\FrontendUser
{
/**
* @var \Vendor\ExtKey\Domain\Model\ContactPerson
*/
protected $contactPerson = null;
}
并覆盖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,
),
);
但当我打电话:
/**
* 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();
}
}
它会创建以下SQL-错误:
'where子句‘中未知列'fe_users.contact_person’
发布于 2016-10-11 15:00:53
计算的双向1:1关系在TYPO3中不受支持,只有m:n关系支持具有额外TCA中的定义的关系--这也需要在关系的相反位置增加一个字段。
关于您的场景,您必须自己在扩展的FrontendUser
域模型中创建附加属性和数据库字段。
发布于 2021-02-10 16:45:01
有一种可能,如本文所述:http://www.oliver-weiss.com/blog/einzelansicht/article/relationen-in-typo3-teil-1-11-relation/News/detail/。另外,如果只有一方是“内联”的,而另一方是“选择”的话,而不是在双方都有“内联”关系时,这也是有效的。但是,单个(倒排)“内联”关系需要定义"foreign_field“。在此之后,"foreign“uid只存储在关系的一侧。
https://stackoverflow.com/questions/39979314
复制相似问题