dblayeroo: allow the foreign keys to be a NOT NULL field, then not be tested
git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@4002 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
@@ -2726,7 +2726,8 @@ class dblayeroo
|
||||
// recorded
|
||||
if ($update === true && ! array_key_exists ($field, $values))
|
||||
continue 2;
|
||||
if (! array_key_exists ($field, $values))
|
||||
if (! array_key_exists ($field, $values) &&
|
||||
in_array ("not null", $this->fields[$field]))
|
||||
{
|
||||
$errors[$field] = sprintf (dgettext ("domframework",
|
||||
"The field '%s' must be test on foreign, but is not provided"),
|
||||
@@ -2737,6 +2738,9 @@ class dblayeroo
|
||||
$this->DBException (sprintf (dgettext ("domframework",
|
||||
"No foreign object configured to test the foreign key for table ".
|
||||
"'%s'"), $this->table));
|
||||
if (! array_key_exists ($field, $values) &&
|
||||
! in_array ("not null", $this->fields[$field]))
|
||||
$values[$field] = null;
|
||||
}
|
||||
$this->debugLog ("CLONE to check foreign constraint [$fields]");
|
||||
$objTmp = clone $this->setForeignObj[$params[0]];
|
||||
@@ -2746,8 +2750,21 @@ class dblayeroo
|
||||
$objTmp->Select ();
|
||||
$objTmp->displayAdd ($objTmp->primary);
|
||||
$parentField = explode (",", $params[1]);
|
||||
$i = 0;
|
||||
foreach (explode (",", $fields) as $key=>$field)
|
||||
$objTmp->whereAdd ($parentField[$key], "=", $values[$field]);
|
||||
{
|
||||
if ($values[$field] !== null)
|
||||
{
|
||||
$objTmp->whereAdd ($parentField[$key], "=", $values[$field]);
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
if ($i == 0)
|
||||
{
|
||||
// If the foreign is null, do not test as there is no WHERE clause, and
|
||||
// will return all the table
|
||||
continue;
|
||||
}
|
||||
if (count ($objTmp->execute ()) === 0)
|
||||
$errors[$field] = sprintf (dgettext ("domframework",
|
||||
"The value of the foreign key '%s' doesn't exists in foreign table"),
|
||||
|
||||
Reference in New Issue
Block a user