I have a one-to-one relation between Team
and Coach
. I use has one edit module to edit the Coach's name directly via the Team
gridfield edit page.
On the first Team
save, two Coach
records are created with the supplied names. However on each consecutive save a new Coach
record is created, which is obviously not the desired outcome. Instead, it should save the updated names to the same records, because the coaches don't change, it's just their columns (names) that change.
Team
class Team extends DataObject {
private static $has_one {
'MainCoach' => 'Coach',
'AssistentCoach' => 'Coach'
);
}
Coach
class Coach extends DataObject {
private static $db = array(
'Name' => 'Varchar'
);
Team edit page
public function getCMSFields() {
TextField::create('MainCoach-_1_-Name', 'Main coach name'), // main coach name
TextField::create('AssistentCoach-_1_-Name', 'Assistent coach name') // assistent coach name
}