From a0842afd474058c08bdcc14f62ddc28df057a94e Mon Sep 17 00:00:00 2001 From: philipp lang Date: Fri, 8 Mar 2024 01:26:40 +0100 Subject: [PATCH] Add participants parent id --- app/Form/Fields/NamiField.php | 2 +- .../migrations/2024_02_04_032520_create_participants_table.php | 1 + tests/Feature/Form/FormRegisterActionTest.php | 3 +++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/Form/Fields/NamiField.php b/app/Form/Fields/NamiField.php index 36149206..d952fd67 100644 --- a/app/Form/Fields/NamiField.php +++ b/app/Form/Fields/NamiField.php @@ -119,7 +119,7 @@ class NamiField extends Field } $data[$this->key] = []; - $form->participants()->create(['data' => $data, 'mitgliedsnr' => $memberData['id']]); + $form->participants()->create(['data' => $data, 'mitgliedsnr' => $memberData['id'], 'parent_id' => $participant->id]); } } diff --git a/database/migrations/2024_02_04_032520_create_participants_table.php b/database/migrations/2024_02_04_032520_create_participants_table.php index 2c747078..41971c98 100644 --- a/database/migrations/2024_02_04_032520_create_participants_table.php +++ b/database/migrations/2024_02_04_032520_create_participants_table.php @@ -17,6 +17,7 @@ return new class extends Migration $table->id(); $table->json('data'); $table->foreignId('form_id'); + $table->foreignId('parent_id', 'participants')->nullable(); $table->string('mitgliedsnr')->nullable(); $table->timestamps(); }); diff --git a/tests/Feature/Form/FormRegisterActionTest.php b/tests/Feature/Form/FormRegisterActionTest.php index 04e32411..dfbca8a6 100644 --- a/tests/Feature/Form/FormRegisterActionTest.php +++ b/tests/Feature/Form/FormRegisterActionTest.php @@ -308,6 +308,7 @@ class FormRegisterActionTest extends FormTestCase $this->register($form, ['email' => 'max@muster.de'])->assertOk(); $this->assertNull($form->participants->first()->mitgliedsnr); + $this->assertNull($form->participants->first()->parent_id); } // --------------------------- NamiField Tests --------------------------- @@ -329,6 +330,8 @@ class FormRegisterActionTest extends FormTestCase $this->assertEquals([['id' => '5505'], ['id' => '5506']], $form->participants->get(0)->data['members']); $this->assertEquals([], $form->participants->get(1)->data['members']); $this->assertEquals([], $form->participants->get(2)->data['members']); + $this->assertEquals($form->participants->get(0)->id, $form->participants->get(2)->parent_id); + $this->assertEquals($form->participants->get(0)->id, $form->participants->get(1)->parent_id); } protected function memberMatchingDataProvider(): Generator