From f03515df4f01a020cf59c36cb46509e0deb1df7e Mon Sep 17 00:00:00 2001 From: Jose Carlos Laura Ramirez Date: Tue, 3 Dec 2024 20:54:42 -0400 Subject: [PATCH 1/2] =?UTF-8?q?[TM-1539]=20add=20validation=20for=20relati?= =?UTF-8?q?onships=20in=20linked=20fields=20that=20are=20=E2=80=A6=20(#597?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [TM-1539] add validation for relationships in linked fields that are not iterables --- app/Models/Traits/UsesLinkedFields.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Models/Traits/UsesLinkedFields.php b/app/Models/Traits/UsesLinkedFields.php index 68be03d2a..f76a6dff6 100644 --- a/app/Models/Traits/UsesLinkedFields.php +++ b/app/Models/Traits/UsesLinkedFields.php @@ -225,7 +225,7 @@ private function mapValue($model, string $property, array $linkedFieldInfo) if (empty($resource)) { return $model->$relation; } - if (empty($model->$relation)) { + if (empty($model->$relation) || ! is_iterable($model->$relation)) { return []; } From b10e5ac25a423111198269540c0b0f891bc37fc3 Mon Sep 17 00:00:00 2001 From: Nathan Curtis Date: Wed, 4 Dec 2024 10:30:29 -0800 Subject: [PATCH 2/2] [TM-1539] Fix the underlying issue with workdays --- .../Resources/V2/ProjectReports/ProjectReportResource.php | 4 ++-- app/Models/Traits/HasWorkdays.php | 4 ++-- app/Models/Traits/UsesLinkedFields.php | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/Http/Resources/V2/ProjectReports/ProjectReportResource.php b/app/Http/Resources/V2/ProjectReports/ProjectReportResource.php index 8d63ce409..c39000056 100644 --- a/app/Http/Resources/V2/ProjectReports/ProjectReportResource.php +++ b/app/Http/Resources/V2/ProjectReports/ProjectReportResource.php @@ -118,8 +118,8 @@ public function toArray($request) 'people_knowledge_skills_increased' => $this->people_knowledge_skills_increased, 'indirect_beneficiaries' => $this->indirect_beneficiaries, 'indirect_beneficiaries_description' => $this->indirect_beneficiaries_description, - 'workdays_direct_total' => $this->workdays_direct, - 'workdays_convergence_total' => $this->workdays_convergence, + 'workdays_direct_total' => $this->workdays_direct_total, + 'workdays_convergence_total' => $this->workdays_convergence_total, 'non_tree_total' => $this->non_tree_total, 'total_community_partners' => $this->total_community_partners, ]; diff --git a/app/Models/Traits/HasWorkdays.php b/app/Models/Traits/HasWorkdays.php index ec97f8b45..8e88a0c47 100644 --- a/app/Models/Traits/HasWorkdays.php +++ b/app/Models/Traits/HasWorkdays.php @@ -42,12 +42,12 @@ public function getWorkdaysVolunteerAttribute(): int return $this->sumTotalWorkdaysAmounts(self::WORKDAY_COLLECTIONS['volunteer']); } - public function getWorkdaysDirectAttribute(): int + public function getWorkdaysDirectTotalAttribute(): int { return $this->sumTotalWorkdaysAmounts(self::WORKDAY_COLLECTIONS['direct']); } - public function getWorkdaysConvergenceAttribute(): int + public function getWorkdaysConvergenceTotalAttribute(): int { return $this->sumTotalWorkdaysAmounts(self::WORKDAY_COLLECTIONS['convergence']); } diff --git a/app/Models/Traits/UsesLinkedFields.php b/app/Models/Traits/UsesLinkedFields.php index f76a6dff6..68be03d2a 100644 --- a/app/Models/Traits/UsesLinkedFields.php +++ b/app/Models/Traits/UsesLinkedFields.php @@ -225,7 +225,7 @@ private function mapValue($model, string $property, array $linkedFieldInfo) if (empty($resource)) { return $model->$relation; } - if (empty($model->$relation) || ! is_iterable($model->$relation)) { + if (empty($model->$relation)) { return []; }