diff --git a/lib/models/Modul.php b/lib/models/Modul.php index a3d7d9c31a5b1aae2b443d1ab512d8cae574f4d8..80e2753854e6de0c37e9e91eb557d98be26bd4dc 100644 --- a/lib/models/Modul.php +++ b/lib/models/Modul.php @@ -397,15 +397,21 @@ class Modul extends ModuleManagementModelTreeItem if (!$institute) { return false; } - if ($this->responsible_institute && $this->responsible_institute->institut_id != $institut_id) { - $this->responsible_institute && $this->responsible_institute->delete(); - $resp_institute = new ModulInst(); - $resp_institute->institut_id = $institute->id; - $resp_institute->modul_id = $this->id; - $resp_institute->gruppe = 'hauptverantwortlich'; - $this->responsible_institute = $resp_institute; + + if (!$this->responsible_institute || $this->responsible_institute->institut_id !== $institut_id) { + if ($this->responsible_institute) { + $this->responsible_institute->delete(); + } + + $this->responsible_institute = ModulInst::build([ + 'institut_id' => $institute->id, + 'modul_id' => $this->id, + 'gruppe' => 'hauptverantwortlich', + ]); } + $this->assigned_institutes->unsetBy('institut_id', $institute->id); + return true; }