2
將表格值寫入外部關係領域的最佳方式是什麼?SilverStripe如何寫入外國關係的領域
我需要將$coachField
的值保存到外表中的特定列中。 IE:在Team
對象窗體中,我需要能夠保存Coach
的名稱(其中記錄具有一對一關係)。
我傾向於在Team
使用onAfterWrite得到教練的名字,但我不知道如何在第一時間檢索值和高於一切,如果這將是最好的方法。
當前數據對象
class Team extends DataObject {
// The value needs to be saved in Coach->Name
private static $has_one = array(
'Coach' => 'Coach'
);
public function getCMSFields() {
// The form field where to get the value from
$coachField = TextField::create('CoachName', 'Who is the coach');
}
}
國外數據對象
class Coach extends DataObject {
// Here's where the name should be written to
private static $db = array(
'Name' => 'Varchar'
);
private static $belongs_to = array(
'Team' => 'Team'
);
}
工程就像一個魅力。 – Faloude