diff --git a/lib/models/SimpleORMap.class.php b/lib/models/SimpleORMap.class.php
index b35293b67284511a48cb8ab2de2c822ba3601824..a86696adf3a17740fa9e0ec3f7277d25776951ae 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']));
                      }