问题描述
我使用SilverStripe4和ModelAdmin来管理数据对象.
Im using SilverStripe4 and the ModelAdmin to manage DataObjects.
DataObject在文件上具有has_one.到目前为止,一切正常,但是在前端控制器上,文件"关系中有一个空对象.
The DataObject has a has_one on File. Everything works so far but on frontend controller the File relation has an empty object.
我看到该文件不在File_Live表中,所以我猜它没有发布,因此在前端控制器上找不到它.
I see that the file is not in the File_Live table, so i guess its not published and therefor its not found on the frontend controller.
如何从ModelAdmin发布文件关系?基本上,文件上传后应该自动发布.
How can i publish File relations from the ModelAdmin?Basically when a file is uploaded it should be automatically published.
我想如果我使用版本化的DataObjects,我仍然需要这样的东西: https://github.com/drzax/silverstripe-bits/tree/master/VersionedModelAdmin
在ModelAdmin上具有发布机制.
I guess if i use versioned DataObjects i would still need something like this: https://github.com/drzax/silverstripe-bits/tree/master/VersionedModelAdmin
to have publish mechanism on ModelAdmin.
或者SS4中内置了什么?还会将其降级到文件关系吗?
Or is there something builtin in SS4?Would this cascade down to File relations as well?
修改:关于版本化的DataObjects,SS4中有一个内置的发布按钮只需使用:
regarding versioned DataObjects there is a built in publish button in SS4just use:
private static $extensions = [
Versioned::class,
];
private static $versioned_gridfield_extensions = true;
推荐答案
您可以将以下内容添加到DataObject中:
You can add the following to your DataObject:
private static $owns = ['FileRelationName'];
具有关系的示例:
private static $has_one = ['File' => File::class];
private static $owns = ['File'];
任何以此方式声明为拥有"的相关对象将与DataObject
本身一起发布.
Any related object that is being declared as "owned" in this way will be published with the DataObject
itself.
这篇关于ModelAdmin中的Silverstripe文件关系未发布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!