我有两个这样创建的表:
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,但不会丢弃与其相关的表中的其他属性。
我错过了什么?
发布于 2016-08-15 19:43:15
这不是它的工作方式。cascade意味着当您从cvs表中删除一些CV时,具有相同cv_id的所有行都将从educations表中删除。您不能期望整个表都会被删除。
https://stackoverflow.com/questions/38954388
复制相似问题