Skip to content

Commit 55c4845

Browse files
authored
Merge pull request #11379 from greg0ire/3.1.x
Merge 2.19.x up into 3.1.x
2 parents 7178b9d + a38f473 commit 55c4845

File tree

6 files changed

+110
-9
lines changed

6 files changed

+110
-9
lines changed

docs/.gitignore

Lines changed: 0 additions & 4 deletions
This file was deleted.

docs/.gitmodules

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/UnitOfWork.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2581,9 +2581,9 @@ public function createEntity(string $className, array $data, array &$hints = [])
25812581

25822582
if ($hints['fetchMode'][$class->name][$field] === ClassMetadata::FETCH_EAGER) {
25832583
$isIteration = isset($hints[Query::HINT_INTERNAL_ITERATION]) && $hints[Query::HINT_INTERNAL_ITERATION];
2584-
if (! $isIteration && $assoc->isOneToMany()) {
2584+
if (! $isIteration && $assoc->isOneToMany() && ! $targetClass->isIdentifierComposite) {
25852585
$this->scheduleCollectionForBatchLoading($pColl, $class);
2586-
} elseif (($isIteration && $assoc->isOneToMany()) || $assoc->isManyToMany()) {
2586+
} else {
25872587
$this->loadCollection($pColl);
25882588
$pColl->takeSnapshot();
25892589
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Doctrine\Tests\Models\EagerFetchedCompositeOneToMany;
6+
7+
use Doctrine\Common\Collections\ArrayCollection;
8+
use Doctrine\Common\Collections\Collection;
9+
use Doctrine\ORM\Mapping as ORM;
10+
11+
#[ORM\Entity]
12+
#[ORM\Table(name: 'eager_composite_join_root')]
13+
class RootEntity
14+
{
15+
#[ORM\Id]
16+
#[ORM\Column(type: 'integer', nullable: false)]
17+
private int|null $id = null;
18+
19+
#[ORM\Id]
20+
#[ORM\Column(type: 'string', nullable: false, name: 'other_key', length: 42)]
21+
private string $otherKey;
22+
23+
/** @var Collection<int, SecondLevel> */
24+
#[ORM\OneToMany(mappedBy: 'root', targetEntity: SecondLevel::class, fetch: 'EAGER')]
25+
private Collection $secondLevel;
26+
27+
public function __construct(int $id, string $other)
28+
{
29+
$this->otherKey = $other;
30+
$this->secondLevel = new ArrayCollection();
31+
$this->id = $id;
32+
}
33+
34+
public function getId(): int|null
35+
{
36+
return $this->id;
37+
}
38+
39+
public function getOtherKey(): string
40+
{
41+
return $this->otherKey;
42+
}
43+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Doctrine\Tests\Models\EagerFetchedCompositeOneToMany;
6+
7+
use Doctrine\ORM\Mapping as ORM;
8+
9+
#[ORM\Entity]
10+
#[ORM\Table(name: 'eager_composite_join_second_level')]
11+
#[ORM\Index(name: 'root_other_key_idx', columns: ['root_other_key', 'root_id'])]
12+
class SecondLevel
13+
{
14+
#[ORM\Id]
15+
#[ORM\Column(type: 'integer', nullable: false)]
16+
private int|null $upperId;
17+
18+
#[ORM\Id]
19+
#[ORM\Column(type: 'string', nullable: false, name: 'other_key')]
20+
private string $otherKey;
21+
22+
#[ORM\ManyToOne(targetEntity: RootEntity::class, inversedBy: 'secondLevel')]
23+
#[ORM\JoinColumn(name: 'root_id', referencedColumnName: 'id')]
24+
#[ORM\JoinColumn(name: 'root_other_key', referencedColumnName: 'other_key')]
25+
private RootEntity $root;
26+
27+
public function __construct(RootEntity $upper)
28+
{
29+
$this->upperId = $upper->getId();
30+
$this->otherKey = $upper->getOtherKey();
31+
$this->root = $upper;
32+
}
33+
34+
public function getId(): int|null
35+
{
36+
return $this->id;
37+
}
38+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Doctrine\Tests\ORM\Functional;
6+
7+
use Doctrine\Tests\Models\EagerFetchedCompositeOneToMany\RootEntity;
8+
use Doctrine\Tests\Models\EagerFetchedCompositeOneToMany\SecondLevel;
9+
use Doctrine\Tests\OrmFunctionalTestCase;
10+
11+
final class EagerFetchOneToManyWithCompositeKeyTest extends OrmFunctionalTestCase
12+
{
13+
/** @ticket 11154 */
14+
public function testItDoesNotThrowAnExceptionWhenTriggeringALoad(): void
15+
{
16+
$this->setUpEntitySchema([RootEntity::class, SecondLevel::class]);
17+
18+
$a1 = new RootEntity(1, 'A');
19+
20+
$this->_em->persist($a1);
21+
$this->_em->flush();
22+
23+
$this->_em->clear();
24+
25+
self::assertCount(1, $this->_em->getRepository(RootEntity::class)->findAll());
26+
}
27+
}

0 commit comments

Comments
 (0)