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具有多态关系
删除一个。 b和c由于级联而删除。但相关模型e或f不会删除。我该如何实现它。
你可以覆盖类C
delete
方法并在那里做逻辑:
public function delete() {
set e to Collection<E>;
set d to Collection<D>;
if parent::delete() is true
remove e;
remove d;
}