diff --git a/docs/.gitignore b/docs/.gitignore deleted file mode 100644 index 59cd005a9a4..00000000000 --- a/docs/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -en/_exts/configurationblock.pyc -build -en/_build -.idea diff --git a/docs/.gitmodules b/docs/.gitmodules deleted file mode 100644 index e38d44b0adf..00000000000 --- a/docs/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "en/_theme"] - path = en/_theme - url = https://github.com/doctrine/doctrine-sphinx-theme.git diff --git a/src/UnitOfWork.php b/src/UnitOfWork.php index 018c1e788fb..f6a30a0028c 100644 --- a/src/UnitOfWork.php +++ b/src/UnitOfWork.php @@ -2581,9 +2581,9 @@ public function createEntity(string $className, array $data, array &$hints = []) if ($hints['fetchMode'][$class->name][$field] === ClassMetadata::FETCH_EAGER) { $isIteration = isset($hints[Query::HINT_INTERNAL_ITERATION]) && $hints[Query::HINT_INTERNAL_ITERATION]; - if (! $isIteration && $assoc->isOneToMany()) { + if (! $isIteration && $assoc->isOneToMany() && ! $targetClass->isIdentifierComposite) { $this->scheduleCollectionForBatchLoading($pColl, $class); - } elseif (($isIteration && $assoc->isOneToMany()) || $assoc->isManyToMany()) { + } else { $this->loadCollection($pColl); $pColl->takeSnapshot(); } diff --git a/tests/Tests/Models/EagerFetchedCompositeOneToMany/RootEntity.php b/tests/Tests/Models/EagerFetchedCompositeOneToMany/RootEntity.php new file mode 100644 index 00000000000..d369be822d9 --- /dev/null +++ b/tests/Tests/Models/EagerFetchedCompositeOneToMany/RootEntity.php @@ -0,0 +1,43 @@ + */ + #[ORM\OneToMany(mappedBy: 'root', targetEntity: SecondLevel::class, fetch: 'EAGER')] + private Collection $secondLevel; + + public function __construct(int $id, string $other) + { + $this->otherKey = $other; + $this->secondLevel = new ArrayCollection(); + $this->id = $id; + } + + public function getId(): int|null + { + return $this->id; + } + + public function getOtherKey(): string + { + return $this->otherKey; + } +} diff --git a/tests/Tests/Models/EagerFetchedCompositeOneToMany/SecondLevel.php b/tests/Tests/Models/EagerFetchedCompositeOneToMany/SecondLevel.php new file mode 100644 index 00000000000..0608dcffba4 --- /dev/null +++ b/tests/Tests/Models/EagerFetchedCompositeOneToMany/SecondLevel.php @@ -0,0 +1,38 @@ +upperId = $upper->getId(); + $this->otherKey = $upper->getOtherKey(); + $this->root = $upper; + } + + public function getId(): int|null + { + return $this->id; + } +} diff --git a/tests/Tests/ORM/Functional/EagerFetchOneToManyWithCompositeKeyTest.php b/tests/Tests/ORM/Functional/EagerFetchOneToManyWithCompositeKeyTest.php new file mode 100644 index 00000000000..82b9d0b8acb --- /dev/null +++ b/tests/Tests/ORM/Functional/EagerFetchOneToManyWithCompositeKeyTest.php @@ -0,0 +1,27 @@ +setUpEntitySchema([RootEntity::class, SecondLevel::class]); + + $a1 = new RootEntity(1, 'A'); + + $this->_em->persist($a1); + $this->_em->flush(); + + $this->_em->clear(); + + self::assertCount(1, $this->_em->getRepository(RootEntity::class)->findAll()); + } +}