remove entry totals from Doubler database. Save list of entries for each doubler.
This commit is contained in:
parent
a27b8166e2
commit
630efaf00f
|
|
@ -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(),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue