onBeforeWrite()
たぶん、フックで textField 値をキャッチできます
$fields->addFieldToTab('Root.Main', new TextField('ILikeCountCount', 'ILikeCount', $this->ILikeCount()->Count), 'Content');
textField の名前は何でもかまいません。ここでは、わかりやすくするためにドット表記を削除しました。次に、値をキャッチしonBeforeWrite()
てリレーションを更新します。
public function onBeforeWrite()
{
if( $this->ILikeCountCount )
{
// check if a $has_on realtion exist
if ( !$this->ILikeCountID )
{
// create new DataObject + relation
$ILikeCount = ILikeCount::create();
$ILikeCount->Count = $this->ILikeCountCount;
$ILikeCount->write();
$this->ILikeCountID = $ILikeCount->ID;
}
else{
// update existing relation
$ILikeCount = $this->ILikeCount();
$ILikeCount->Count = $this->ILikeCountCount;
$ILikeCount->write();
}
$this->ILikeCountCount = false; // clear to avoid duplicate writes
}
parent::onBeforeWrite();
}