@@ -65,27 +65,21 @@ public function preload(
6565 }
6666
6767 $ maxFetchJoinSameFieldCount ??= 1 ;
68- $ sourceEntities = $ this ->loadProxies ($ sourceClassMetadata , $ sourceEntities , $ batchSize ?? self ::PRELOAD_ENTITY_DEFAULT_BATCH_SIZE , $ maxFetchJoinSameFieldCount , $ readOnly );
68+ $ sourceEntities = $ this ->loadProxies (
69+ $ sourceClassMetadata ,
70+ $ sourceEntities ,
71+ $ batchSize ?? self ::PRELOAD_ENTITY_DEFAULT_BATCH_SIZE ,
72+ $ maxFetchJoinSameFieldCount ,
73+ $ readOnly ,
74+ );
6975
7076 $ preloader = match ($ associationMapping ['type ' ]) {
7177 ClassMetadata::ONE_TO_ONE , ClassMetadata::MANY_TO_ONE => $ this ->preloadToOne (...),
7278 ClassMetadata::ONE_TO_MANY , ClassMetadata::MANY_TO_MANY => $ this ->preloadToMany (...),
7379 default => throw new LogicException ("Unsupported association mapping type {$ associationMapping ['type ' ]}" ),
7480 };
7581
76- $ result = $ preloader ($ sourceEntities , $ sourceClassMetadata , $ sourcePropertyName , $ targetClassMetadata , $ batchSize , $ maxFetchJoinSameFieldCount , $ readOnly );
77-
78- if ($ readOnly ) {
79- $ unitOfWork = $ this ->entityManager ->getUnitOfWork ();
80-
81- foreach ($ result as $ entity ) {
82- if (!$ unitOfWork ->isReadOnly ($ entity )) {
83- $ unitOfWork ->markReadOnly ($ entity );
84- }
85- }
86- }
87-
88- return $ result ;
82+ return $ preloader ($ sourceEntities , $ sourceClassMetadata , $ sourcePropertyName , $ targetClassMetadata , $ batchSize , $ maxFetchJoinSameFieldCount , $ readOnly );
8983 }
9084
9185 /**
@@ -328,7 +322,7 @@ private function preloadManyToManyInner(
328322
329323 $ sourceIdentifierType = $ this ->getIdentifierFieldType ($ sourceClassMetadata );
330324
331- $ manyToManyQuery = $ this ->entityManager ->createQueryBuilder ()
325+ $ manyToManyRows = $ this ->entityManager ->createQueryBuilder ()
332326 ->select ("source. {$ sourceIdentifierName } AS sourceId " , "target. {$ targetIdentifierName } AS targetId " )
333327 ->from ($ sourceClassMetadata ->getName (), 'source ' )
334328 ->join ("source. {$ sourcePropertyName }" , 'target ' )
@@ -338,13 +332,9 @@ private function preloadManyToManyInner(
338332 $ this ->convertFieldValuesToDatabaseValues ($ sourceIdentifierType , $ uninitializedSourceEntityIdsChunk ),
339333 $ this ->deduceArrayParameterType ($ sourceIdentifierType ),
340334 )
341- ->getQuery ();
342-
343- if ($ readOnly ) {
344- $ manyToManyQuery ->setHint (Query::HINT_READ_ONLY , true );
345- }
346-
347- $ manyToManyRows = $ manyToManyQuery ->getResult ();
335+ ->getQuery ()
336+ ->setHint (Query::HINT_READ_ONLY , $ readOnly )
337+ ->getResult ();
348338
349339 $ targetEntities = [];
350340 $ uninitializedTargetEntityIds = [];
@@ -459,13 +449,10 @@ private function loadEntitiesBy(
459449 $ queryBuilder ->addOrderBy ("{$ rootLevelAlias }. {$ field }" , $ direction );
460450 }
461451
462- $ query = $ queryBuilder ->getQuery ();
463-
464- if ($ readOnly ) {
465- $ query ->setHint (Query::HINT_READ_ONLY , true );
466- }
467-
468- return $ query ->getResult ();
452+ return $ queryBuilder
453+ ->getQuery ()
454+ ->setHint (Query::HINT_READ_ONLY , $ readOnly )
455+ ->getResult ();
469456 }
470457
471458 private function deduceArrayParameterType (Type $ dbalType ): ArrayParameterType |int |null // @phpstan-ignore return.unusedType (old dbal compat)
0 commit comments