From 731194cba01b149467568af1247b4c6c08c16aca Mon Sep 17 00:00:00 2001 From: Hamza-Ayed Date: Fri, 28 Aug 2026 23:18:18 +0300 Subject: [PATCH] fix: multi-child demo linking in Guardian portal --- backend/app/Controllers/GuardianController.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/backend/app/Controllers/GuardianController.php b/backend/app/Controllers/GuardianController.php index 4a8fa6e..0f573d2 100644 --- a/backend/app/Controllers/GuardianController.php +++ b/backend/app/Controllers/GuardianController.php @@ -25,14 +25,16 @@ class GuardianController [$guardianId] ); - // If no children linked (for demo purposes, link all students or the first one if empty) + // If no children linked (for demo purposes, link up to 3 students so the multi-child UI can be tested) if (empty($children)) { - $demoStudent = Database::selectOne("SELECT id FROM students LIMIT 1"); - if ($demoStudent) { - Database::insert( - "INSERT IGNORE INTO guardian_students (guardian_id, student_id, relationship_type) VALUES (?, ?, 'father')", - [$guardianId, $demoStudent['id']] - ); + $demoStudents = Database::select("SELECT id FROM students LIMIT 3"); + if (!empty($demoStudents)) { + foreach ($demoStudents as $demoStudent) { + Database::insert( + "INSERT IGNORE INTO guardian_students (guardian_id, student_id, relationship_type) VALUES (?, ?, 'father')", + [$guardianId, $demoStudent['id']] + ); + } // Re-fetch $children = Database::select( "SELECT s.id, s.uuid, s.full_name, s.national_id, s.grade_level, s.stream