File tree 2 files changed +11
-19
lines changed
2 files changed +11
-19
lines changed Original file line number Diff line number Diff line change @@ -441,7 +441,15 @@ protected function correctTypes() : static
441
441
}
442
442
else if (\array_key_exists ($ field , $ this ->current ))
443
443
{
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 ])
445
453
{
446
454
case 'int ' :
447
455
$ this ->current [$ field ] = (int )$ this ->current [$ field ];
@@ -485,17 +493,7 @@ public function read(array|int|string $fields) : bool
485
493
*/
486
494
public function reload () : bool
487
495
{
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 ());
499
497
}
500
498
501
499
/**
Original file line number Diff line number Diff line change @@ -782,13 +782,7 @@ public function insert(array $records, string $ignore = '') : bool
782
782
$ tableName = $ this ->getTableName ();
783
783
$ sql = "insert {$ ignore } into ` {$ tableName }` ( " ;
784
784
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 ());
792
786
$ comma = '' ;
793
787
794
788
foreach ($ fields as $ fieldName )
You can’t perform that action at this time.
0 commit comments