michaeldyrynda / laravel-cascade-soft-deletes

Cascading deletes for Eloquent models that implement soft deletes
https://dyrynda.com.au
MIT License
1k stars 76 forks source link

It Doesn't work #53

Closed AnuragckMeridianSolutions closed 2 years ago

AnuragckMeridianSolutions commented 2 years ago

Hi Actually Its not properly working for me. I have the following two models: Menu SubMenu

-->I also added the code on the model but its doesn't works. `class Menu extends Model { use HasFactory; use SoftDeletes; use CascadeSoftDeletes;

protected $cascadeDeletes = ['subMenusFromMenu'];
protected $dates = ['deleted_at'];

public function subMenusFromMenu(): HasMany
{
    return $this->hasMany(SubMenu::class, 'menu_id', 'id');
}

}`

I tried to delete Menu , But after deleting menu the related child submenu records doesn't delete.

michaeldyrynda commented 2 years ago

We don't delete the distant records, only the pivot records, so this is expected behaviour.

See #34.

Mohammad699 commented 2 years ago

I don't understand what should we do to delete these records? I have the same issue, I need to delete children records of some model, how to do it?

michaeldyrynda commented 2 years ago

Records are only detached from the records being deleted.

The package doesn’t look to see if the records being detached are being used in other relationships.

Deleting distant records can lead to orphaned records in the pivot table.