From 8b7f9fe5060e137d574ea82651e4d07b1baff5be Mon Sep 17 00:00:00 2001
From: Jan-Hendrik Willms <tleilax+studip@gmail.com>
Date: Fri, 31 May 2024 08:10:40 +0000
Subject: [PATCH] fixes #4233

Closes #4233

Merge request studip/studip!3066
---
 lib/models/SimpleORMap.class.php | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/lib/models/SimpleORMap.class.php b/lib/models/SimpleORMap.class.php
index b35293b6728..a86696adf3a 100644
--- a/lib/models/SimpleORMap.class.php
+++ b/lib/models/SimpleORMap.class.php
@@ -1553,6 +1553,13 @@ class SimpleORMap implements ArrayAccess, Countable, IteratorAggregate
                              }
                              $this->setValue($options['foreign_key'], $assoc_foreign_key_value);
                          }
+                     } elseif (
+                         $value === null
+                         && $this->db_fields()[$options['foreign_key']]['null'] === 'YES'
+                     ) {
+                         $this->resetRelation($field);
+                         $this->setValue($options['foreign_key'], null);
+
                      } else {
                          throw new InvalidArgumentException(sprintf('relation %s expects object of type: %s', $field, $options['class_name']));
                      }
-- 
GitLab