Problem with $belongs_many_many
Closed this issue · 1 comments
Hi
Next code in class BlogEntry extends DataObject:
public static $belongs_many_many_extraFields=array(
'BlogCategorys'=>array(
'SortOrder'=>'Int'
)
);
not created 'SortOrder' column
Problem is solved with the following code:
class BlogCategory extends Page {
private static $many_many = array(
'BlogEntrys' => 'BlogEntry'
);
public static $many_many_extraFields=array(
'BlogEntrys'=>array(
'SortOrder'=>'Int'
)
);
}
class BlogEntry extends DataObject {
private static $belongs_many_many = array(
'BlogCategorys' => 'BlogCategory'
);
public function getCMSFields() {
...
$gridFieldConfig = GridFieldConfig_RelationEditor::create();
$gridFieldConfig->removeComponentsByType('GridFieldAddNewButton');
$gridFieldConfig->addComponent(new GridFieldSortableRows('SortOrder'));
$gridfield = new GridField("BlogCategorys", "Blog Categorys", $this->BlogCategorys(), $gridFieldConfig);
$fields->addFieldToTab('Root.BlogCategorys', $gridfield);
...
}
public function BlogCategorys() {
return $this->getManyManyComponents('BlogCategorys')->sort('SortOrder');
}
}
The problem with this code has been solved.
But why is not working with $belongs_many_many_extraFields ?
Well this is really an issue with SilverStripe's ORM not SortableGridField, my guess the idea here is that you define the extra fields on the object that defines the many_many relationship. I''m pretty sure the core of SilverStripe even looks for a belongs_many_many_extraFields. My recommendation is to have a look at the documentation http://doc.silverstripe.org/framework/en/reference/dataobject. If you think that this is a feature the SilverStripe core is missing try raising it there silverstripe/silverstripe-framework