在 SilverStripe 中管理 has_one 内联关系

Managing has_one relation inline in SilverStripe

我想知道是否可以在 SilverStripe 中直接编辑 has_one 关系的值。

例如:

PersonSiteTree 的扩展名)有一个 JobDataObject 的扩展名),其中 Job 有 title、salary、位置等

在 CMS 中是否可以在新选项卡中放置一个表单来编辑 Person 页面中 Job 的值?因此,Job DataObject 中的所有表单字段都放在 Person 页面上,当我在 Person 上点击保存时,它们将保存到 Job table页数?

我可以让它与内联网格字段编辑一起工作(感谢 editable columns class in gridfieldextensions),但我相信这需要 has_many / many_many 关系?它也不适合添加图像和管理具有大量字段的对象。

我希望这是有道理的。如果您需要更多说明,请告诉我。

编辑: 我发现 this hasonefield module 这是非常过时的,但它完成了我所追求的 80%,如果它不采取,那将是惊人的不过你离开了页面,你可以编辑父页面中的字段 (Person)。

有一个 fork of simon's orginal has-one-edit module 仍然可用并且可以安装 composer,它执行编辑 has_one 关系的字段(或所有字段)的逻辑。安装它 运行

composer require stevie-mayhew/hasoneedit:1.0.x@stable

然后你可以定义你的has one relation的几个字段,命名应该是HasOneName-_1_-FieldName.

来自文档:

For example, say you have a has_one called Show and that has_one has a field called Title you want to edit. You'd add the field TextField::create('Show-_1_-Title', 'Show Title').

To add support to your own forms, you need to add the sgn_hasoneedit_UpdateFormExtension extension to your controller and call $this->extend('updateEditForm', $form) before returning the form to the template. Without this, the fields will not get populated with the values from the has_one though saving will work.