Skip to content

Commit 36fc3af

Browse files
committed
Nulls are valid in fields allowing nulls
1 parent 9c87bf0 commit 36fc3af

File tree

2 files changed

+11
-19
lines changed

2 files changed

+11
-19
lines changed

src/PHPFUI/ORM/Record.php

+10-12
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,15 @@ protected function correctTypes() : static
441441
}
442442
else if (\array_key_exists($field, $this->current))
443443
{
444-
switch ($row[1])
444+
// don't touch nulls if allowed by the field or the primary key
445+
if ($this->current[$field] === null)
446+
{
447+
if ($row[self::ALLOWS_NULL_INDEX] || in_array($field, static::$primaryKeys))
448+
{
449+
continue;
450+
}
451+
}
452+
switch ($row[self::PHP_TYPE_INDEX])
445453
{
446454
case 'int':
447455
$this->current[$field] = (int)$this->current[$field];
@@ -485,17 +493,7 @@ public function read(array|int|string $fields) : bool
485493
*/
486494
public function reload() : bool
487495
{
488-
$keys = [];
489-
490-
foreach (static::$primaryKeys as $key)
491-
{
492-
if (\array_key_exists($key, $this->current))
493-
{
494-
$keys[$key] = $this->current[$key];
495-
}
496-
}
497-
498-
return $this->read($keys);
496+
return $this->read($this->getPrimaryKeyValues());
499497
}
500498

501499
/**

src/PHPFUI/ORM/Table.php

+1-7
Original file line numberDiff line numberDiff line change
@@ -782,13 +782,7 @@ public function insert(array $records, string $ignore = '') : bool
782782
$tableName = $this->getTableName();
783783
$sql = "insert {$ignore} into `{$tableName}` (";
784784

785-
// remove primary keys
786-
$fieldDefinitions = $this->getFields();
787-
foreach ($this->getPrimaryKeys() as $key)
788-
{
789-
unset($fieldDefinitions[$key]);
790-
}
791-
$fields = \array_keys($fieldDefinitions);
785+
$fields = \array_keys($this->getFields());
792786
$comma = '';
793787

794788
foreach ($fields as $fieldName)

0 commit comments

Comments
 (0)