我正在做一个使用Typo3 9.5.14和扩展构建器9.10.2的项目。我有一个与“标签”-model具有1:N关系的“提供者”-model。它看起来像这样:Extension Builder provider-label relation
我的目标是:通过HTML表单编辑连接到特定提供者的标签的值。目前,我的实现如下所示。
我有一个具有"companyProfileSaveAction“方法的控制器。该方法有效,并允许我设置provider-Model的属性。它看起来是这样的:
public function companyProfileSaveAction(Provider $provider)
{
$persistenceManager = $this->objectManager->get(\TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager::class);
if ($provider->getUid()) {
$this->providerRepository->update($provider);
} else {
$this->providerRepository->add($provider);
}
$persistenceManager->persistAll();
$this->redirect('companyProfilePage', null, null, ['provider' => $provider, 'saved' => true]);
}这里提到的providerRepository扩展了\TYPO3cms\Extbase\Persistence\Repository。函数"update“和"add”来自于这个继承。
现在我尝试使用这个函数来添加或编辑提供者的标签,这些标签是通过上面提到的1:N关系连接的。我通过html表单发送数据。数据基本上看起来像这样:
tx_my_extension[provider][labels][0][name]: label 1
tx_my_extension[[provider][labels][0][text]: description 1
tx_my_extension[[provider][labels][1][name]: label 2
tx_my_extension[[provider][labels][1][text]: description 2
tx_my_extension[[provider][labels][2][name]: label 3
tx__my_extension[[provider][labels][2][text]: description 3这也是可行的,标签被创建并连接到提供程序。但是现在,作为一个例子,假设我想这样编辑我的标签:
tx_my_extension[provider][labels][0][name]: label 1 edited
tx_my_extension[[provider][labels][0][text]: description 1
tx_my_extension[[provider][labels][1][name]: label 2 edited
tx_my_extension[[provider][labels][1][text]: description 2
tx_my_extension[[provider][labels][2][name]: label 3 edited
tx__my_extension[[provider][labels][2][text]: description 3当我像这样发送它时,旧的三个标签与我的提供者完全断开连接,并创建了三个新标签。随着时间的推移,我的数据库中充满了许多断开连接的标签,这些标签没有任何用途。与每次保存表单时都创建新标签不同,我如何编辑已存在的标签?
发布于 2021-07-29 21:31:18
自从我使用TYPO3的这些部分以来,已经有一段时间了,但是:
您是否尝试过添加__identity虚拟post字段,例如tx_my_extension[provider][labels][0][__identity]: 123,其中的值是相关对象的UID?
这应该使属性映射器在将值映射到属性之前获取该对象,这反过来应该意味着您的根实体仍然与子项相关,并且子项被标记为“脏”,然后被持久化。
https://stackoverflow.com/questions/68575181
复制相似问题