【发布时间】:2013-07-29 23:56:15
【问题描述】:
添加 many_many 关系时,很像 silverstripe 指南中的项目与导师关系:
http://doc.silverstripe.org/framework/en/tutorials/5-dataobject-relationship-management
我想根据关系记录一个属性。因此,例如“活动” - 项目导师的是/否字段。但是,对于与她相关的不同项目,导师可能对活跃有不同的价值。
使用 Silverstripe 的内置工具实现这一目标的最佳方法是什么?
更新 在 IRC 的帮助下和下面的答案。我离得更近了一点,它不起作用。我发现了这个: https://github.com/chillu/silverstripe-framework/blob/c8136f5d4c8a37a4da274cd1c93907c0a2af86a7/docs/en/reference/grid-field.md 这似乎非常相关。
因此,DebatePages 有 many_many 小组成员,他们可以对每场辩论进行不同的投票。
辩论页面.php
private static $many_many = array(
'Panelists' => 'Panelist',
'RelationTags' => 'Tag'
);
public static $many_many_extraFields = array(
'Panelists' => array('Motion' => 'Boolean')
);
public function getCMSFields() {
.....
if($this->ID) {
$panelistFields = singleton('Panelist')->getCMSFields();
$panelistFields->addFieldToTab(
'Root.Main',
// Please follow the "ManyMany[<extradata-name>]" convention
new TextField('ManyMany[Motion]', 'Agree with Motion')
);
$config = GridFieldConfig_RelationEditor::create();
$config->getComponentByType('GridFieldDetailForm')->setFields($panelistFields);
$gridField = new GridField('Panelists', 'Panelists', $this->Panelists(), $config);
$fields->findOrMakeTab('Root.Panelists')->replaceField('Panelist', $gridField);
}
}
【问题讨论】:
标签: silverstripe