diff --git a/application/Espo/ORM/BaseEntity.php b/application/Espo/ORM/BaseEntity.php index 7569330049..45760a5030 100644 --- a/application/Espo/ORM/BaseEntity.php +++ b/application/Espo/ORM/BaseEntity.php @@ -1007,6 +1007,12 @@ class BaseEntity implements Entity } if (is_array($item)) { + if (!array_is_list($item)) { + $copy[$i] = $this->cloneObject((object) $item); + + continue; + } + $copy[$i] = $this->cloneArray($item); continue; diff --git a/tests/unit/Espo/ORM/EntityTest.php b/tests/unit/Espo/ORM/EntityTest.php index 25e9eca51b..e25041f4bf 100644 --- a/tests/unit/Espo/ORM/EntityTest.php +++ b/tests/unit/Espo/ORM/EntityTest.php @@ -340,6 +340,37 @@ class EntityTest extends TestCase $this->assertEquals(json_decode($value), $entity->get('object')); } + public function testGetJsonArray(): void + { + $entity = $this->createEntity('Job'); + + $entity->set('array', [0, 1]); + $this->assertEquals([0, 1], $entity->get('array')); + + $entity->set('array', [[0], [1]]); + $this->assertEquals([[0], [1]], $entity->get('array')); + + $entity->set('array', [ + (object) ['test' => 0], + (object) ['test' => 1], + ]); + + $this->assertEquals([ + (object) ['test' => 0], + (object) ['test' => 1], + ], $entity->get('array')); + + $entity->set('array', [ + ['test' => 0], + ['test' => 1], + ]); + + $this->assertEquals([ + (object) ['test' => 0], + (object) ['test' => 1], + ], $entity->get('array')); + } + public function testSetWrongType() { $entity = $this->createEntity('Test');