Skip to content

Commit 3af2e36

Browse files
committed
Added handling of collection attribute to correctly initialize property's data
1 parent 91ae604 commit 3af2e36

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/Model/Insert/PrepareEntityArray.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,25 @@ public function iterateVariables(
7373
}
7474

7575
foreach ($attributes as $attribute) {
76-
if ($attribute->getName() === \Spameri\Elastic\Mapping\STIEntity::class) {
76+
if ($attribute->getName() === \Spameri\Elastic\Mapping\Collection::class) {
77+
if ($property === null) {
78+
continue 2;
79+
}
80+
81+
/** @var \Spameri\Elastic\Entity\EntityInterface $item */
82+
foreach ($property as $item) {
83+
$collectionItemData = $this->iterateVariables(
84+
$item->entityVariables(),
85+
$this->reflection->createReflection($item::class),
86+
);
87+
$collectionItemData[self::ENTITY_CLASS] = $item::class;
88+
89+
$preparedArray[$key][] = $collectionItemData;
90+
}
91+
92+
continue 2;
93+
94+
} elseif ($attribute->getName() === \Spameri\Elastic\Mapping\STIEntity::class) {
7795
if ($property === null) {
7896
continue 2;
7997
}

0 commit comments

Comments
 (0)