1

我正在尝试使用简单树特征来实现父/子关系。

我在文档中附加了它作为悲伤

在后端,我使用表单构建器添加了一个关系字段以使父元素可选,即 fields.yaml 文件

fields:
    name:
        label: 'name'
        oc.commentPosition: ''
        span: full
        required: 1
        type: text
    image:
        label: 'image'
        oc.commentPosition: ''
        mode: image
        span: full
        type: mediafinder
    parent_id:
        label: Relation
        oc.commentPosition: ''
        nameFrom: name
        descriptionFrom: description
        span: auto
        type: relation

错误模型不包含 parent_id 的定义。

<?php namespace depcore\parts\Models;
use Model;

/**
 * Model
 */
class Series extends Model
{
    use \October\Rain\Database\Traits\Validation;
    use \October\Rain\Database\Traits\SimpleTree;

    /*
     * Disable timestamps by default.
     * Remove this line if timestamps are defined in the database table.
     */
    public $timestamps = false;

    /*
     * Validation
     */
    public $rules = [
    ];

    /**
     * @var string The database table used by the model.
     */
    public $table = 'depcore_parts_series';

    /**
     * Relations
     */
    public $attachOne = [
      'image' =>'System\Models\File'
    ];

}

我在文档中找不到任何信息如何实现关系,以便用户在添加新元素时可以选择父元素。

4

1 回答 1

1

好的,因此在模型的后端表单中挖掘解决方案非常简单,而不是parent_id字段应该是parent完整的代码看起来像

fields:
    name:
        label: 'name'
        oc.commentPosition: ''
        span: full
        required: 1
        type: text
    image:
        label: 'image'
        oc.commentPosition: ''
        mode: image
        span: full
        type: mediafinder
    parent:
        label: 'parent'
        oc.commentPosition: ''
        nameFrom: name
        descriptionFrom: description
        span: auto
        type: relation
于 2017-09-20T08:36:18.517 回答