- Added a new initialized variable checking before adding (or not) a new value to an entity

This commit is contained in:
Dave Mc Nicoll 2025-09-09 13:00:05 -04:00
parent 0e0f004bc1
commit 5d6d7ff49c

View File

@ -51,9 +51,12 @@ abstract class Save implements \Picea\Ui\Method\FormInterface {
)); ));
} }
} }
catch(\Throwable $ex) { catch(\PDOException $ex) {
throw new \PDOException($this->lang('lean.api.form.save.error.pdo', [ 'error' => $ex->getMessage() ])); throw new \PDOException($this->lang('lean.api.form.save.error.pdo', [ 'error' => $ex->getMessage() ]));
} }
catch(\Throwable $ex) {
throw $ex;
}
return $saved; return $saved;
} }
@ -69,7 +72,8 @@ abstract class Save implements \Picea\Ui\Method\FormInterface {
if ($apiField) { if ($apiField) {
$var = $apiField->field ?: $key; $var = $apiField->field ?: $key;
if ( isset($context->{$var}) ) {
if ( property_exists($context, $var) && ( new \ReflectionProperty($context, $var) )->isInitialized($context) ) {
if ($apiField->setterMethod) { if ($apiField->setterMethod) {
# Use a setter method # Use a setter method
call_user_func([ $entity, $apiField->setterMethod ], $context->{$var}); call_user_func([ $entity, $apiField->setterMethod ], $context->{$var});