我可以在 Silverstripe 中管理与 Gridfield(或类似)的 has_one 关系吗?

Can I manage a has_one relationship with Gridfield (or similar) in Silverstripe?

我们有一个对象与 Silverstripe 项目中的次要对象有 has_one 关系。次要对象有多个 has_one 字段

class IceCream extends DataObject
{

  private static $has_one = [
    'Cone' => 'Cone'
  ]
}

class Cone extends DataObject
{
  private static $has_one = [
    'Size' => 'Size',
    'Pattern' => 'Pattern'
  ]

}

我们希望能够从 CMS 中的 IceCream 对象编辑次要对象 Cone。创建新的 Cone 记录或 linking 现有的 Cone 记录。

如果 Cone 处于 many_many 关系中,我们可以将 Gridfieldsymbiote/silverstripe-gridfieldextensions 模块一起使用。并使用 GridFieldAddExistingSearchButton & GridFieldAddNewInlineButton 扩展。

是否可以在 has_one 关系中使用这种行为?

我已经使用 stevie-mayhew/hasoneedit 模块进行了调查,但它似乎只启用了 has_one 字段的内联编辑(在本例中为 SizePattern)并且没有启用似乎不允许用户 link 现有 Cone 记录。

我们如何在 CMS 中创建一个允许用户 link 或创建 has_one 记录的字段 - 最好是内联或模态?

您可以使用几个模块来执行此操作。

我们的偏好是https://github.com/satrun77/silverstripe-hasoneselector, some other community members prefer to use https://github.com/silvershop/silverstripe-hasonefield, which is also a dependency of quite widely used https://github.com/gorriecoe/silverstripe-linkfield。在支持方面可能是更好的选择。