@@ -354,15 +354,14 @@ private function createInitializer(ClassMetadata $classMetadata, EntityPersister
354
354
/**
355
355
* Creates a closure capable of initializing a proxy
356
356
*
357
- * @return Closure(InternalProxy, InternalProxy ):void
357
+ * @return Closure(InternalProxy, array ):void
358
358
*
359
359
* @throws EntityNotFoundException
360
360
*/
361
361
private function createLazyInitializer (ClassMetadata $ classMetadata , EntityPersister $ entityPersister , IdentifierFlattener $ identifierFlattener ): Closure
362
362
{
363
- return static function (InternalProxy $ proxy ) use ($ entityPersister , $ classMetadata , $ identifierFlattener ): void {
364
- $ identifier = $ classMetadata ->getIdentifierValues ($ proxy );
365
- $ original = $ entityPersister ->loadById ($ identifier );
363
+ return static function (InternalProxy $ proxy , array $ identifier ) use ($ entityPersister , $ classMetadata , $ identifierFlattener ): void {
364
+ $ original = $ entityPersister ->loadById ($ identifier );
366
365
367
366
if ($ original === null ) {
368
367
throw EntityNotFoundException::fromClassNameAndIdentifier (
@@ -378,7 +377,7 @@ private function createLazyInitializer(ClassMetadata $classMetadata, EntityPersi
378
377
$ class = $ entityPersister ->getClassMetadata ();
379
378
380
379
foreach ($ class ->getReflectionProperties () as $ property ) {
381
- if (! $ class ->hasField ($ property ->name ) && ! $ class ->hasAssociation ($ property ->name )) {
380
+ if (isset ( $ identifier [ $ property -> name ]) || ! $ class ->hasField ($ property ->name ) && ! $ class ->hasAssociation ($ property ->name )) {
382
381
continue ;
383
382
}
384
383
@@ -468,7 +467,9 @@ private function getProxyFactory(string $className): Closure
468
467
$ identifierFields = array_intersect_key ($ class ->getReflectionProperties (), $ identifiers );
469
468
470
469
$ proxyFactory = Closure::bind (static function (array $ identifier ) use ($ initializer , $ skippedProperties , $ identifierFields , $ className ): InternalProxy {
471
- $ proxy = self ::createLazyGhost ($ initializer , $ skippedProperties );
470
+ $ proxy = self ::createLazyGhost (static function (InternalProxy $ object ) use ($ initializer , $ identifier ): void {
471
+ $ initializer ($ object , $ identifier );
472
+ }, $ skippedProperties );
472
473
473
474
foreach ($ identifierFields as $ idField => $ reflector ) {
474
475
if (! isset ($ identifier [$ idField ])) {
0 commit comments