From 630efaf00f882eae9b3cc01c695be838137a322a Mon Sep 17 00:00:00 2001 From: Matt Young Date: Mon, 23 Jun 2025 00:52:19 -0500 Subject: [PATCH] remove entry totals from Doubler database. Save list of entries for each doubler. --- app/Models/Doubler.php | 16 ++++++++++++---- .../2025_06_20_175904_create_doublers_table.php | 1 - 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/app/Models/Doubler.php b/app/Models/Doubler.php index 907aca3..0da8d7a 100644 --- a/app/Models/Doubler.php +++ b/app/Models/Doubler.php @@ -5,8 +5,6 @@ namespace App\Models; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; -use function PHPUnit\Framework\isInstanceOf; - class Doubler extends Model { // Specify that we're not using a single primary key @@ -16,6 +14,10 @@ class Doubler extends Model protected $guarded = []; + protected $casts = [ + 'entries' => 'array', + ]; + public function student(): BelongsTo { return $this->belongsTo(Student::class); @@ -39,7 +41,8 @@ class Doubler extends Model */ public static function syncForEvent($eventId): void { - if (isInstanceOf(Event::class, $eventId)) { + + if ($eventId instanceof Event) { $eventId = $eventId->id; } @@ -61,6 +64,11 @@ class Doubler extends Model } else { $acceptedEntryId = null; } + + // Form a list of entry IDs for this doubler + $entryList = []; + $entryList = $student->entriesForEvent($eventId)->pluck('id')->toArray(); + // Create or update the doubler record static::updateOrCreate( [ @@ -68,8 +76,8 @@ class Doubler extends Model 'event_id' => $eventId, ], [ + 'entries' => $entryList, 'accepted_entry' => $acceptedEntryId, - 'entry_count' => $student->entriesForEvent($eventId)->count(), ] ); } diff --git a/database/migrations/2025_06_20_175904_create_doublers_table.php b/database/migrations/2025_06_20_175904_create_doublers_table.php index 32cae70..60208c9 100644 --- a/database/migrations/2025_06_20_175904_create_doublers_table.php +++ b/database/migrations/2025_06_20_175904_create_doublers_table.php @@ -20,7 +20,6 @@ return new class extends Migration $table->foreignIdFor(Event::class)->constrained()->cascadeOnDelete()->cascadeOnUpdate(); // Doubler Specific Fields - $table->integer('entry_count'); $table->json('entries')->nullable(); $table->foreignIdFor(Entry::class, 'accepted_entry')->nullable()->constrained('entries')->cascadeOnDelete()->cascadeOnUpdate();