首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >TYPO3 Extbase: InversedBy 1:1关系

TYPO3 Extbase: InversedBy 1:1关系
EN

Stack Overflow用户
提问于 2016-10-11 14:14:51
回答 2查看 890关注 0票数 0

在Extbase中,是否可以在不向DB中添加第二个字段的情况下逆1:1关系?

例如:扩展有联系人-人员,可以有一个fe_user。联系人-人-域-模型是关系的所有者站点.

现在您可以使用$contactPerson->getFrontendUser();

有没有办法在不将其添加到DB的情况下向FrontendUser添加反向属性?

所以你可以使用$frontendUser->getContactPerson()

或者更重要的是:$frontendUserRepository->findByContactPerson()

我尝试将该属性添加到FrontendUser Model中:

代码语言:javascript
运行
复制
/**
 * FrontendUser
 */
class FrontendUser extends \TYPO3\CMS\Extbase\Domain\Model\FrontendUser
{

    /**
     * @var \Vendor\ExtKey\Domain\Model\ContactPerson
     */
    protected $contactPerson = null;
}

并覆盖fe_users TCA:

代码语言:javascript
运行
复制
$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,
    ),
);

但当我打电话:

代码语言:javascript
运行
复制
/**
 * 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’

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-10-11 15:00:53

计算的双向1:1关系在TYPO3中不受支持,只有m:n关系支持具有额外TCA中的定义的关系--这也需要在关系的相反位置增加一个字段。

关于您的场景,您必须自己在扩展的FrontendUser域模型中创建附加属性和数据库字段。

票数 2
EN

Stack Overflow用户

发布于 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只存储在关系的一侧。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39979314

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档