如何在cascate中执行删除? 我有两个对象,人物和联系人。
一个人有很多联系人,当我删除人们需要删除所有联系人时,该怎么做?
删除功能
Host
myapp.com
Path
/
Protocol
HTTP
Port
80
Proxy protocol
NONE
Interval
5 seconds
Timeout
5 seconds
Unhealthy threshold
2 consecutive failures
Healthy threshold
2 consecutive successes
迁移人员
public function destroy($id)
{
$people= $this->ModelPeople->find($id);
$people= $people->delete();
}
迁移联系
public function up()
{
Schema::create('Peoples', function (Blueprint $table) {
$table->increments('id');
$table->string('name',100);
$table->integer('sex');
$table->integer('active');
$table->timestamps();
});
}
模拟人物和联系人
public function up()
{
Schema::create('contacts', function (Blueprint $table) {
$table->increments('id');
$table->integer('idpeople')->unsigned();
$table->foreign('idpeople')->references('id')->on('people')->onDelete('cascade');
$table->string('cel',20)->nullable();
$table->string('email',100)->nullable();
$table->timestamps();
});
}
使用此方案删除一个人时,所有联系人都应该删除吗?或者这不是自动的,我必须删除控制器中我的destroy方法中的联系人?