@@ -360,9 +360,8 @@ private function createInitializer(ClassMetadata $classMetadata, EntityPersister
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 (
@@ -375,10 +374,11 @@ private function createLazyInitializer(ClassMetadata $classMetadata, EntityPersi
375
374
return ;
376
375
}
377
376
378
- $ class = $ entityPersister ->getClassMetadata ();
377
+ $ class = $ entityPersister ->getClassMetadata ();
378
+ $ identifiers = array_flip ($ class ->getIdentifierFieldNames ());
379
379
380
380
foreach ($ class ->getReflectionProperties () as $ property ) {
381
- if (! $ class ->hasField ($ property ->name ) && ! $ class ->hasAssociation ($ property ->name )) {
381
+ if (isset ( $ identifiers [ $ property -> name ]) || ! $ class ->hasField ($ property ->name ) && ! $ class ->hasAssociation ($ property ->name )) {
382
382
continue ;
383
383
}
384
384
@@ -468,7 +468,9 @@ private function getProxyFactory(string $className): Closure
468
468
$ identifierFields = array_intersect_key ($ class ->getReflectionProperties (), $ identifiers );
469
469
470
470
$ proxyFactory = Closure::bind (static function (array $ identifier ) use ($ initializer , $ skippedProperties , $ identifierFields , $ className ): InternalProxy {
471
- $ proxy = self ::createLazyGhost ($ initializer , $ skippedProperties );
471
+ $ proxy = self ::createLazyGhost (static function (InternalProxy $ object ) use ($ initializer , $ identifier ): void {
472
+ $ initializer ($ object , $ identifier );
473
+ }, $ skippedProperties );
472
474
473
475
foreach ($ identifierFields as $ idField => $ reflector ) {
474
476
if (! isset ($ identifier [$ idField ])) {
0 commit comments