A migration
function up() {
$table->increments('id');
}
B migration
function up() {
$table->increments('id');
$table->integer('a_id')->unsigned();
$table->foreign('a_id')
->references('id')
->on('as')
->onDelete('cascade')
->onDelete('cascade');
}
C migration
function up() {
$table->increments('id')
$table->integer('b_id')->unsigned();
$table->foreign('b_id')
->references('id')
->on('as')
->onDelete('cascade')
->onDelete('cascade');
}
c也与D,E具有多态关系
删除a。 b和c由于级联而删除。但相关模型e或f不会删除。我该如何实现呢。
答案 0 :(得分:0)
您可以覆盖类C
delete
方法并在那里执行逻辑:
public function delete() {
set e to Collection<E>;
set d to Collection<D>;
if parent::delete() is true
remove e;
remove d;
}