I have one PageType CompanyPage which has many Companies and many Regions.
Each Company can be active in many Regions.
When I create a company, I want to assign several regions to it.
Like this, but in the Company editscreen:
http://doc.silverstripe.com/lib/exe/fetch.php?w=&h=&cache=cache&media=tutorial:gsoc-mentor-student-selection.png
So I need multiple CTF's but can't figure it out wich relations I need and which CTF's I need to manage them.
I can add Companies and Regions to the CompanyPage, but I can't assign Regions to a Company when editting a Company.
This are the realtions that I now have
class CompanyPage extends Page {
public static $db = array(
);
static $has_many = array (
'Companies' => 'Company',
'Regions' => 'Region'
);
}
class Company extends DataObject {
static $db = array (
'Name' => 'Varchar'
);
static $has_one = array (
'Logo' => 'Image',
'CompanyPage' => 'CompanyPage'
);
static $many_many = array(
'Regions' => 'Region'
);
}
class Region extends DataObject {
static $db = array (
'Name' => 'Varchar'
);
static $has_one = array(
'CompanyPage' => 'CompanyPage'
);
static $belongs_many_many = array(
'Companies' => 'Company'
);
}
On the CompanyPage I have 2 HasManyComplexTableFields for showing the Companies and Regions in a seperate tab. This works as expected.
I can add Regions. No problem.
Now when I add a ManyManyComplexTableField to the Company class I get this error:
Fatal error: Call to a member function Regions() on a non-object in D:\xampp\xampp\htdocs\silver_snippets\sapphire\forms\HasManyComplexTableField.php on line 91
When I add a HasManyComplexTableField I get:
Can't find a has_one relationship from 'Region' to 'Company'
So when I add a $has_one to the Region class, I can choose a Company on creating a new Regio. But it doesn't save the Company to the Region..
Can someone point me to the right direction to relate this 3 classes and how to administer them?