From e0238705cc89222c1ecce9b8319f09c1b21f1f91 Mon Sep 17 00:00:00 2001 From: TuxGasy Date: Sat, 14 Sep 2019 19:04:43 +0200 Subject: [PATCH] Check if childtablesoncascade is not empty --- htdocs/core/class/commonobject.class.php | 26 +++++++++++++----------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index d20a8d2785b..f08be052e96 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -7536,18 +7536,20 @@ abstract class CommonObject } // Delete cascade first - foreach($this->childtablesoncascade as $table) - { - $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$table.' WHERE '.$this->fk_element.' = '.$this->id; - $resql = $this->db->query($sql); - if (! $resql) - { - $this->error=$this->db->lasterror(); - $this->errors[]=$this->error; - $this->db->rollback(); - return -1; - } - } + if (! empty($this->childtablesoncascade)) { + foreach($this->childtablesoncascade as $table) + { + $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$table.' WHERE '.$this->fk_element.' = '.$this->id; + $resql = $this->db->query($sql); + if (! $resql) + { + $this->error=$this->db->lasterror(); + $this->errors[]=$this->error; + $this->db->rollback(); + return -1; + } + } + } if (! $error) { if (! $notrigger) {