Hi Guys/Girls
Let me start by saying that I'm new to SilverStripe but loving it! I have a background in PHP, CodeIgniter, and Drupal. Let's just say that Drupal is going bye-bye :)
That being said, I am having issues getting many_many relationships to sync correctly on ManyManyComplexTableField tables. I'm sure it is something simple - but I've searched and scoured and tried various alterations - all to no avail (eg. setParentClass, using belong_many_many, even trying to specify the join on the ManyManyComplexTableField, etc).
I have two DataObjects that I wish to be able to manipulate in the CMS backend: 'Feature' and 'PlanType'. Each PlanType can have multiple Features, and each Feature may be applicable to multiple plans. I can get the options for PlanType to show up on Feature and v.v.
However:
- If I add a PlanType and check that it has a certain Feature on the ManyManyComplexTableField it will record and save the value without issue
- If I then go to Feature and look at the ManyManyComplexTableField, it does NOT show that PlanType is linked
I have figured out that this is because the database is creating two tables instead of using the one table (ie. it is creating Feature_PlanTypes AND PlanType_Feature). Each side of the relationship is using separate tables rather that the one.
How (in dear God's name) do I get both sides of the many_many relationship to use the same table rather (and thus syncing) rather than using the two separate tables generated by SS.
I'm sure it is simple.
Please forgive me if this does not make sense - I'm frustrated and writing late at night.
For your reference I have included the 'offending' PHP files:
MyFeatureAdmin.php -> CMS admin
<?php
class MyFeatureAdmin extends ModelAdmin {
public static $managed_models = array (
'Feature',
'PlanType'
);
static $url_segment = 'features';
static $menu_title = 'Features';
}
?>
Feature.php -> Feature DataObject
<?php
class Feature extends DataObject {
static $db = array('Feature' => 'Varchar(100)');
static $many_many = array('PlanTypes' => 'PlanType'); //link to PlanType DataModel
static $summary_fields = array('Feature');
function getCMSFields(){
$fields = parent::getCMSFields();
$tablefield = new ManyManyComplexTableField($this, 'PlanTypes', 'PlanType', array('Type'=>'Type'), 'getCMSFields');
$fields->addFieldToTab('Root.PlanTypes', $tablefield);
return $fields;
}
}
?>
PlanType.php -> PlanType DataObject
<?php
class PlanType extends DataObject {
static $db = array('Type' => 'Varchar(100)');
static $many_many = array('Features' => 'Feature');
static $summary_fields = array( 'Type');
function getCMSFields(){
$fields = parent::getCMSFields();
$tablefield = new ManyManyComplexTableField($this, 'Features', 'Feature', array('Feature'=>'Feature'), 'getCMSFields');
$fields->addFieldToTab('Root.Features', $tablefield);
return $fields;
}
}
?>
If I could just get this sorted - SS would be the be-all in my world.
Thanks for any input.