Ok i had a look at the code. To fix your problems you need to look at the following. I tested it om my side and it works.
------------------------------------------------------
Konzert.php
-------------------------------------------------------
class Konzert extends DataObject {
static $db=array(
'KonzertName'=>'Varchar(150)',
'DoorsOpen'=>'Varchar(150)'
);
static $has_one = array(
// Left side is the name of relationship --- right hand side is the class is related to. This has_one relationship creates a column called
// BandsID in our Konzert table to show Silverstripe that there is a relationship between the two classes
'Bands'=>'Band'
);
// Sets the sumary fields that will be displayed in the grid field
static $summary_fields = array(
'KonzertName',
'DoorsOpen'
);
function getCMSFields() {
// to populate drowp down field for 'Band' it needs a source. We then 'map' the 'ID' col as the the one used to store values in database
// and 'Name' is the name of the band ---- see code for 'Band.php'
$BandDropdown = Dataobject::get("Band")->map("ID", "Name");
// create new field list and remember we need to add our has_one field 'Band' in as well
$fields = new FieldList (
new TextField('KonzertName', 'Name of the Konzert'),
new TextField('DoorsOpen', 'Doors Open'),
// The drop down field has 4 parameters:
// 1) Name of the field that we are saving to. In our case it is has one relationship called 'Bands' that created a <br />
// field called BandsID in the table called Konzeret.
// 2) The description 'Bands Playing'
// 3) The values we want in our drop down menu we created above
// 4) We leave params 4 and 5 open and set the deefault message for the drop down to 'Please select'
new DropdownField('BandsID', 'Bands Playing', $BandDropdown,'','','--Please Select--')
);
return $fields;
}
// Now we set validation for our Data Object Fields
public function getCMSValidator() {
return new RequiredFields(
'KonzertName',
// Remember our drop down field references the has_one relationship with the field BandsID
'BandsID',
'DoorsOpen'
);
}
}
---------------------------------------------------
Band.php
----------------------------------------------------
class Band extends DataObject {
static $db=array(
'Name'=>'Varchar(150)'
);
function getCMSFields() {
$fields = new FieldList (
new TextField('Name', 'Band Name')
);
return $fields;
}
}