【问题标题】:TYPO3 Extbase: InversedBy 1:1 RelationTYPO3 Extbase:InversedBy 1:1 关系
【发布时间】:2016-10-11 14:14:51
【问题描述】:

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

示例: 该扩展具有可以具有 fe_user 的联系人。 Contact-Person-Domain-Model 是关系的拥有站点。

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

有没有办法在不将其添加到数据库的情况下将反转属性添加到 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”

【问题讨论】:

    标签: typo3 extbase


    【解决方案1】:

    TYPO3 不支持计算的双向 1:1 关系,只有 m:n 关系支持额外的 definition in TCA - 这也需要在关系的对面站点上附加一个字段。

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

    【讨论】:

      【解决方案2】:

      有一种可能性,如下所述:http://www.oliver-weiss.com/blog/einzelansicht/article/relationen-in-typo3-teil-1-11-relation/News/detail/。此外,如果只有一侧是“内联”而另一侧是“选择”,这也不是在两侧都有“内联”关系。但是单个(反向)“内联”关系需要定义“foreign_field”。在此之后,“外部”uid 仅存储在关系的一侧。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-11-15
        • 1970-01-01
        • 1970-01-01
        • 2021-11-25
        • 2014-04-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多