@@ -38,6 +38,8 @@ class: $class,
3838 return $ entity ;
3939 }
4040
41+ $ this ->identityMap ->creatingEntityList [$ class ][$ hit ->id ()] = true ;
42+
4143 $ properties = $ this ->resolveProperties (
4244 hit: $ hit ,
4345 class: $ class ,
@@ -52,6 +54,15 @@ class: $class,
5254
5355 $ this ->identityMap ->add ($ entity );
5456
57+ if (isset ($ this ->identityMap ->uninitializedEntityList [$ class ][$ hit ->id ()]) === true ) {
58+ foreach ($ this ->identityMap ->uninitializedEntityList [$ class ][$ hit ->id ()] as $ propertyName => $ notCompletedEntity ) {
59+ $ notCompletedEntity ->$ propertyName = $ entity ;
60+ unset($ this ->identityMap ->uninitializedEntityList [$ class ][$ hit ->id ()]);
61+ }
62+
63+ unset($ this ->identityMap ->creatingEntityList [$ class ][$ hit ->id ()]);
64+ }
65+
5566 return $ entity ;
5667 }
5768
@@ -192,10 +203,17 @@ class: $propertyTypeName,
192203 } elseif (
193204 $ attribute ->getName () === \Spameri \Elastic \Mapping \STIElasticEntity::class
194205 ) {
195- $ propertyValue = $ entityManager ->find (
196- id: $ value [\Spameri \Elastic \Model \Insert \PrepareEntityArray::ENTITY_ID ],
197- class: $ value [\Spameri \Elastic \Model \Insert \PrepareEntityArray::ENTITY_CLASS ],
198- );
206+ if (isset ($ this ->identityMap ->creatingEntityList [$ value [\Spameri \Elastic \Model \Insert \PrepareEntityArray::ENTITY_CLASS ]][$ value [\Spameri \Elastic \Model \Insert \PrepareEntityArray::ENTITY_ID ]])) {
207+ $ parentClass = $ value [\Spameri \Elastic \Model \Insert \PrepareEntityArray::ENTITY_CLASS ];
208+ $ propertyValue = eval ("return (new class() extends $ parentClass {public function __construct(){}}); " );
209+ $ this ->identityMap ->uninitializedEntityList [$ parentClass ][$ value [\Spameri \Elastic \Model \Insert \PrepareEntityArray::ENTITY_ID ]][$ property ->getName ()] = $ propertyValue ;
210+
211+ } else {
212+ $ propertyValue = $ entityManager ->find (
213+ id: $ value [\Spameri \Elastic \Model \Insert \PrepareEntityArray::ENTITY_ID ],
214+ class: $ value [\Spameri \Elastic \Model \Insert \PrepareEntityArray::ENTITY_CLASS ],
215+ );
216+ }
199217
200218 $ this ->changeSet ->markExisting ($ propertyValue );
201219
@@ -218,10 +236,16 @@ class: $value[\Spameri\Elastic\Model\Insert\PrepareEntityArray::ENTITY_CLASS],
218236 isset (\class_implements ($ propertyTypeName )[\Spameri \Elastic \Entity \ElasticEntityInterface::class]) === true
219237 && \is_string ($ value ) === true
220238 ) {
221- $ propertyValue = $ entityManager ->find (
222- id: $ value ,
223- class: $ propertyTypeName ,
224- );
239+ if (isset ($ this ->identityMap ->creatingEntityList [$ propertyTypeName ][$ value ])) {
240+ $ propertyValue = eval ("return (new class() extends $ propertyTypeName {public function __construct(){}}); " );
241+ $ this ->identityMap ->uninitializedEntityList [$ propertyTypeName ][$ value ][$ property ->getName ()] = $ propertyValue ;
242+
243+ } else {
244+ $ propertyValue = $ entityManager ->find (
245+ id: $ value ,
246+ class: $ propertyTypeName ,
247+ );
248+ }
225249
226250 } elseif ($ this ->container ->getByType ($ propertyTypeName , false ) !== null ) {
227251 $ propertyValue = $ this ->container ->getByType ($ propertyTypeName );
0 commit comments