2016-06-14 74 views
0

enter image description here如何在10月CMS後端數據庫中添加多選值?

未在數據庫中插入多選值。

我fields.yaml代碼是:

related_recipe: 
     label: 'Related Recipe' 
     span: auto 
     nameFrom: recipe_title 
     descriptionFrom: description 
     attributes: {multiple:'multiple'} 
     type: relation 

我的模型代碼是:

public $belongsTo = [ 

        'related_recipe' => [ 
         'Qdata\Taeq\Models\Recipe', 
         'conditions' => 'status = 1' 
         ], 

       ]; 

目前只有一種插在database.need選擇的值在數據庫中添加多個值。任何人都可以解決它嗎?

+0

試試這個.. http://stackoverflow.com/questions/35620124/october-cms-create-a-multi-select-form-field –

+0

@VijayWilson我想設置數據使用類型=「關係」不是部分。 –

回答

0

在這種情況下,您應該使用$ belongsToMany關係。

$ belongsTo表示您的模型與您食譜模型的單個實體相鏈接。

+0

我檢查了$ belongsToMany但沒有爲我工作。謝謝 –

0

要做到這一點與關係,你需要去與「belongsToMany」的關係。例如: 在模型 'related_recipes' => [ 'Qdata\Taeq\Models\Recipe', 'table' => 'pivot_table_name', 'key' => 'foreign_key_of_pivot_table', 'otherKey' => 'other_key', ], 在另一個相關型號 'makers' => [ 'Qdata\Taeq\Models\AnotherModel', 'table' => 'pivot_table_name', 'key' => 'foreign_key_of_pivot_table', 'otherKey' => 'other_key', ], 這將保存在數據庫中的相關數據透視表的多選下拉數據。