I have a nested relationship as follows:
Many Workshops.
Each Workshop has many Units.
Each Unit has one Location and many Instructors.
(Locations and Instructors belong to many Units)
I solved having nested associations by extending location and instructors from page, and putting them in their own holder in the site tree. Units are extended from DataObject, and are included in a tab on the workshops page with a HasManyComplexTableField.
In the popup for Units, I have included two ComplexTableFields. A HasMany for Instructors, and a HasOne for the Location. When I edit one of the Units I've already created (before I added the two ComplexTableFields) it loads fine, but if I try to add a new Unit, it gives me the following error.
Fatal error: Call to a member function Instructors() on a non-object in C:\wamp\www\delta\sapphire\forms\HasManyComplexTableField.php on line 91
That line is the $selectedItems line in the following:
function selectedItemIDs() {
$fieldName = $this->name;
$selectedItems = $this->form->getRecord()->$fieldName();
$itemIDs = array();
foreach($selectedItems as $item) $itemIDs[] = $item->ID;
return $itemIDs;
}
If I comment out the instructors ComplexTableField, the form displays properly, but won't save changes to the location ComplexTableField, which leads me to my second issue.
My second issue is that when I try to edit one of the units I've already added, alter the two ComplexTableFields and press save, it won't retain my changes to either of the two ComplexTableFields.
I've put the contents of unit.php, location.php and instructor.php in a pastie here