2017-09-19 109 views
1

我試圖用Simple Tree Trait實現一個父/子關係。十月CMS SimpleTree後端表單

我們已經附上它作爲傷心的documentation

在後端我用表單生成器添加relatioship領域做出父元素選擇,則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' 
    ]; 

} 

我找不到文檔如何落實的關係,以便增加一個新的時,用戶可以選擇一個父元素中的任何信息。

回答

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