OctoberCMS 数据透视模型 $attachOne 关系

OcotberCMS PivotModel $attachOne relation

我正在尝试与 OcotberCMS 中的文件附件枢轴建立 many-to-many 关系。

这是我的亲戚

public $belongsToMany = [
    'users' => [
        User::class,
        'key' => 'task_id',
        'otherKey' => 'user_id',
        'table' => 'tasks_users',
        'pivot' => ['status'],
        'pivotModel' => TaskUser::class
    ]
];

在我的数据透视模型中

class TaskUser extends Pivot
...
public $attachOne = [
    'file' => ['System\Models\File']
];

YAML 配置

pivot:
    form:
        tabs:
            fields:
                pivot[file]:
                    label: Image
                    type: fileupload
                    mode: image
                    span: left
                    tab: Image

表单呈现正确,但在尝试上传文件时,抛出错误: Upload error "A widget with class name 'relationUsersManagePivotFormPivotFile' has not been bound to the controller" on line 605 of D:\Projects\esport\modules\backend\classes\Controller.php

这似乎是关系经理无法处理的大量嵌套。同样 File 不适用于 differed binding 在枢轴模态中使用时。

Relation manager with differed binding pivot data is not supported Ref: https://octobercms.com/docs/backend/relations#belongs-to-many-pivot

所以也许我们可以使用替代方法。如果可以的话。

  1. 在数据透视表 table 中,您可以使用 text type
  2. 添加新字段 file
  3. 在关系配置中指定 => 'pivot' => ['status', 'file']

现在来自现场

pivot:
    form:
        fields:
            pivot[value]:
                label: Value
                type: text
            pivot[file]:
                label: Picture
                type: mediafinder                    

Now you can upload and select files or select existing files. they will be stored as file path so they can directly be accessed.

如有疑问请评论。