So, i have 3 tables MacroAreas, Specific_areas and Services. They're related to each other by one to many relationships. So MacroAreas has many specific areas and so on. I'll copy the migrations here. What I need is that when I delete a "parent" like macroArea it also deletes the related records on specifc area. If I got it right is how the cascading delete should work, no?
So i cannot understand what's wrong here...
Migrations
Schema::create('macro_areas', function (Blueprint $table) {
$table->id();
$table->foreignId('regione_id')->constrained()->onDelete('cascade');
$table->string('nome');
$table->timestamps();
$table->index('nome');
});
Schema::create('specific_areas', function (Blueprint $table) {
$table->id();
$table->foreignId('macroArea_id')->constrained()->onDelete('cascade');
$table->string('nome');
$table->timestamps();
$table->index('nome');
});
Schema::create('services', function (Blueprint $table) {
$table->id();
$table->foreignId('specificArea_id')->constrained()->onDelete('cascade');
$table->string('denominazione')->default('');
$table->string('indirizzo')->nullable();
$table->string('comune')->default('');
$table->integer('cap')->default(0);
$table->string('email')->nullable();
$table->string('pec')->nullable();
$table->string('telefono')->nullable();
$table->string('fax')->nullable();
$table->longText('descrizione')->nullable();
$table->string('sito')->nullable();
$table->timestamps();
$table->index('denominazione');
$table->index('comune');
});
I'll paste the models as well for clarity
macroArea
public function specific_areas()
{
return $this->hasMany(SpecificArea::class, 'macroArea_id');
}
specific
public function macroArea()
{
return $this->belongsTo(MacroArea::class, 'macroArea_id');
}
public function services()
{
return $this->hasmany(Service::class, 'specificArea_id');
}
services
public function specificArea()
{
return $this->belongsTo(SpecificArea::class, 'specificArea_id');
}