Fixed: Delete courses with members
This commit is contained in:
parent
884ad31086
commit
d73bcd376d
|
@ -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());
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue