diff --git a/dblayer.php b/dblayer.php index 53425e2..a4bf152 100644 --- a/dblayer.php +++ b/dblayer.php @@ -437,21 +437,31 @@ class dblayer extends PDO // Check if the foreign keys constrains are valid before doing the insertion foreach ($this->foreign as $foreign=>$data) { - if ($this->debug) echo " verify foreign $foreign\n"; - if (! isset ($datas[$foreign])) + if ($updatekey === false) { - $errors[] = array ("error", sprintf (dgettext("domframework", - "The foreign column '%s' is not provided"), - $foreign)); - return $errors; + // Before doing the insert, check the foreign keys. In update, they are + // not mandatory and are not checked for existancy. + if ($this->debug) echo " verify foreign $foreign\n"; + if (! isset ($datas[$foreign])) + { + $errors[] = array ("error", sprintf (dgettext("domframework", + "The foreign column '%s' is not provided"), + $foreign)); + return $errors; + } + if (! isset ($datas[$foreign][0])) + { + $errors[] = array ("error", sprintf (dgettext("domframework", + "The field type for column '%s' is not provided"), + $foreign)); + return $errors; + continue; + } } - if (! isset ($datas[$foreign][0])) + else { - $errors[] = array ("error", sprintf (dgettext("domframework", - "The field type for column '%s' is not provided"), - $foreign)); - return $errors; - continue; + if (! array_key_exists ($foreign, $data)) + continue; } $table = $data[0]; $column = $data[1];