diff --git a/lib/Entity/Schedule.php b/lib/Entity/Schedule.php index 9ca70a35b2..c76263d78a 100644 --- a/lib/Entity/Schedule.php +++ b/lib/Entity/Schedule.php @@ -499,8 +499,11 @@ public function setOwner($ownerId) */ public function addOrUpdateCriteria(ScheduleCriteria $criteria, ?int $id = null): Schedule { + // set empty array as the default value if original value is empty/null + $originalValue = $this->getOriginalValue('criteria') ?? []; + // Does this already exist? - foreach ($this->getOriginalValue('criteria') as $existing) { + foreach ($originalValue as $existing) { if ($id !== null && $existing->id === $id) { $this->criteria[] = $criteria; return $this;