Fixed: Delete courses with members

This commit is contained in:
philipp lang 2023-04-25 00:32:44 +02:00
parent 884ad31086
commit d73bcd376d
2 changed files with 13 additions and 0 deletions

View File

@ -285,6 +285,7 @@ class Member extends Model
static::deleting(function (self $model): void {
$model->payments->each->delete();
$model->memberships->each->delete();
$model->courses->each->delete();
});
static::saving(fn ($model) => $model->updateSearch());

View File

@ -2,6 +2,8 @@
namespace Tests\Feature\Member;
use App\Course\Models\Course;
use App\Course\Models\CourseMember;
use App\Member\DeleteJob;
use App\Member\Member;
use Carbon\Carbon;
@ -56,4 +58,14 @@ class DeleteTest extends TestCase
app(MemberFake::class)->assertDeleted(123, Carbon::parse('yesterday'));
}
public function testItDeletesMembersWithCourses(): void
{
$this->withoutExceptionHandling()->login()->loginNami();
$member = Member::factory()->defaults()->has(CourseMember::factory()->for(Course::factory()), 'courses')->create();
$member->delete();
$this->assertDatabaseCount('members', 0);
}
}