Silverstripe File relation in ModelAdmin doesnt publish

。_饼干妹妹 提交于 2019-12-31 02:24:06

问题


Im using SilverStripe4 and the ModelAdmin to manage DataObjects.

The DataObject has a has_one on File. Everything works so far but on frontend controller the File relation has an empty object.

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.

How can i publish File relations from the ModelAdmin? Basically when a file is uploaded it should be automatically published.

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.

Or is there something builtin in SS4? Would this cascade down to File relations as well?

Edit: regarding versioned DataObjects there is a built in publish button in SS4 just use:

private static $extensions = [
    Versioned::class,
];

private static $versioned_gridfield_extensions = true;

回答1:


You can add the following to your DataObject:

private static $owns = ['FileRelationName'];

Example with a relation:

private static $has_one = ['File' => File::class];
private static $owns = ['File'];

Any related object that is being declared as "owned" in this way will be published with the DataObject itself.



来源:https://stackoverflow.com/questions/47392211/silverstripe-file-relation-in-modeladmin-doesnt-publish

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!