Silverstripe:使用网格字段中的按钮删除时删除相关数据对象
Silverstripe: delete related dataobjects when deleting with button from a gridfield
我不知道是否可行,但是有没有办法从 GridField 扩展删除按钮?我已经 google 了,但我什么也没找到。
我想向另一个包含我要删除的内容的数据对象添加删除功能。
提前致谢!
如@3dgoo 所述,您可以在 onBeforeDelete()
(api docs) 方法中删除相关内容。
$has_one = [
'Foo' => 'SomeDataobject'
];
/**
* gets called before this item is finally deleted,
* deletes the related "SomeDataObject" also
*/
public function onBeforeDelete()
{
if ($this->FooID) {
$this->Foo()->delete();
}
}
我不知道是否可行,但是有没有办法从 GridField 扩展删除按钮?我已经 google 了,但我什么也没找到。
我想向另一个包含我要删除的内容的数据对象添加删除功能。
提前致谢!
如@3dgoo 所述,您可以在 onBeforeDelete()
(api docs) 方法中删除相关内容。
$has_one = [
'Foo' => 'SomeDataobject'
];
/**
* gets called before this item is finally deleted,
* deletes the related "SomeDataObject" also
*/
public function onBeforeDelete()
{
if ($this->FooID) {
$this->Foo()->delete();
}
}