Skip to content

Commit

Permalink
better handling of int/integer and support setting null on |null columns
Browse files Browse the repository at this point in the history
  • Loading branch information
Hedzer committed Sep 27, 2024
1 parent 70a05b3 commit 2b8ebf7
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions lib/Doctrine/Record.php
Original file line number Diff line number Diff line change
Expand Up @@ -1384,6 +1384,7 @@ protected function _get($fieldName, $load = true)
$value = (string)$value;
break;
case 'integer':
case 'int':
$value = (int)$value;
break;
case 'float':
Expand Down Expand Up @@ -1491,21 +1492,29 @@ protected function _set($fieldName, $value, $load = true)
}
}

switch($type) {
case 'json':
if (!json_validate($value)) {
$value = json_encode($value);
}
break;
case 'decimal':
$value = (string)$value;
break;
case 'float':
$value = (float)$value;
break;
case 'int':
$value = (int)$value;
break;
$cd = $this->_table->getColumnDefinition($fieldName);

$nullable = !array_key_exists('notnull', $cd) || $cd['notnull'] === false;

if (!$nullable || !is_null($value)) {
switch ($type) {
case 'json':
if (!json_validate($value)) {
$value = json_encode($value);
}
break;
case 'decimal':
$value = (string)$value;
break;
case 'doable':
case 'float':
$value = (float)$value;
break;
case 'integer':
case 'int':
$value = (int)$value;
break;
}
}

if ($load) {
Expand Down

0 comments on commit 2b8ebf7

Please sign in to comment.