我创建了两个表:
Schema::create('educations', function(Blueprint $table){
$table->increments('id');
$table->string('title');
$table->date('from_date');
$table->date('to_date');
$table->string('summary');
$table->integer('cv_id')->unsigned();
$table->foreign('cv_id')->references('id')
->on('cvs')
->onDelete('cascade')
->onUpdate('cascade');
$table->timestamps();
});
它们链接到另一个表:
Schema::create('cvs', function(Blueprint $table){
$table->increments('id');
$table->integer('student_id')->unsigned();
$table->foreign('student_id')->references('id')
->on('students')
->onDelete('cascade')
->onUpdate('cascade');
$table->string('summary');
$table->timestamps();
});
问题是,每当我调用这一行时:
$student->cv->delete();
它将删除cv,但不会删除与它相关的表中的其他属性。
不是这样的。cascade
意味着当你从cvs
表中删除一些CV时,所有具有相同cv_id
的行都将从educations
表中删除。