EspoCRM – Open Source CRM Application
PHP calendarcontactscrmcrm-platformcrm-systemcustomer-portalcustomer-supportcustomizabledocumentsemail-marketingkanbanleadsopen-sourcephpplatformsales-automationsingle-page-applicationsupport
Entity empty array to empty object
Yuriib13970e5f238
diff --git a/application/Espo/ORM/BaseEntity.php b/application/Espo/ORM/BaseEntity.phpindex 8170ea38fc..e9a1aabd61 100644--- a/application/Espo/ORM/BaseEntity.php+++ b/application/Espo/ORM/BaseEntity.php@@ -558,6 +558,10 @@ class BaseEntity implements Entity$preparedValue = $value;if (is_array($value)) {+ if ($value === []) {+ return (object) [];+ }+$preparedValue = json_decode(json_encode($value, JSON_THROW_ON_ERROR));if ($preparedValue instanceof stdClass) {diff --git a/tests/unit/Espo/ORM/EntityTest.php b/tests/unit/Espo/ORM/EntityTest.phpindex 8e5843ecd4..5de3c7d105 100644--- a/tests/unit/Espo/ORM/EntityTest.php+++ b/tests/unit/Espo/ORM/EntityTest.php@@ -83,6 +83,15 @@ class EntityTest extends TestCasereturn new $classNameToUse($entityType, $defs, $this->entityManager);}+ public function testObjectAsArray(): void+ {+ $job = $this->createEntity('Job', Job::class);++ $job->set('object', []);++ $this->assertEquals((object) [], $job->get('object'));+ }+public function testIsAttributeChanged(){$job = $this->createEntity('Job', Job::class);