This commit is contained in:
@@ -3,9 +3,12 @@
|
||||
namespace App\Models;
|
||||
|
||||
use CodeIgniter\Model;
|
||||
use App\Models\Concerns\SchoolYearAutoFillTrait;
|
||||
|
||||
class SemesterScoreModel extends Model
|
||||
{
|
||||
use SchoolYearAutoFillTrait;
|
||||
|
||||
protected $table = 'semester_scores';
|
||||
protected $primaryKey = 'id';
|
||||
protected $allowedFields = [
|
||||
@@ -26,6 +29,10 @@ class SemesterScoreModel extends Model
|
||||
'semester',
|
||||
'school_year'
|
||||
];
|
||||
protected $validationRules = [
|
||||
'school_year' => 'required|string|max_length[9]',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* Insert or update a semester score record
|
||||
@@ -34,6 +41,8 @@ class SemesterScoreModel extends Model
|
||||
|
||||
public function upsert(array $data): bool
|
||||
{
|
||||
$data = $this->withDefaultSchoolYear($data);
|
||||
|
||||
// First check if record exists
|
||||
$existing = $this->where([
|
||||
'student_id' => $data['student_id'],
|
||||
@@ -50,4 +59,4 @@ public function upsert(array $data): bool
|
||||
return $this->insert($data) !== false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user