Skip to content

Commit 46e5642

Browse files
committed
Merge remote-tracking branch 'origin/2.20.x' into 3.5.x
2 parents f18de9d + e38278b commit 46e5642

File tree

5 files changed

+47
-7
lines changed

5 files changed

+47
-7
lines changed

phpstan-baseline.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3366,7 +3366,7 @@ parameters:
33663366
-
33673367
message: '#^Access to an undefined property Doctrine\\ORM\\Mapping\\ManyToManyInverseSideMapping\|Doctrine\\ORM\\Mapping\\ManyToManyOwningSideMapping\|Doctrine\\ORM\\Mapping\\ManyToOneAssociationMapping\|Doctrine\\ORM\\Mapping\\OneToManyAssociationMapping\|Doctrine\\ORM\\Mapping\\OneToOneInverseSideMapping\|Doctrine\\ORM\\Mapping\\OneToOneOwningSideMapping\:\:\$mappedBy\.$#'
33683368
identifier: property.notFound
3369-
count: 1
3369+
count: 3
33703370
path: src/UnitOfWork.php
33713371

33723372
-

src/UnitOfWork.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
use function array_sum;
6363
use function array_values;
6464
use function assert;
65+
use function count;
6566
use function current;
6667
use function get_debug_type;
6768
use function implode;
@@ -2594,8 +2595,10 @@ public function createEntity(string $className, array $data, array &$hints = [])
25942595
$reflField->setValue($entity, $pColl);
25952596

25962597
if ($hints['fetchMode'][$class->name][$field] === ClassMetadata::FETCH_EAGER) {
2597-
$isIteration = isset($hints[Query::HINT_INTERNAL_ITERATION]) && $hints[Query::HINT_INTERNAL_ITERATION];
2598-
if (! $isIteration && $assoc->isOneToMany() && ! $targetClass->isIdentifierComposite && ! $assoc->isIndexed()) {
2598+
$isIteration = isset($hints[Query::HINT_INTERNAL_ITERATION]) && $hints[Query::HINT_INTERNAL_ITERATION];
2599+
$isForeignKeyComposite = $assoc->isOneToMany() && $targetClass->hasAssociation($assoc->mappedBy) && count($targetClass->getAssociationMapping($assoc->mappedBy)->joinColumns ?? []) > 1;
2600+
2601+
if (! $isIteration && $assoc->isOneToMany() && ! $isForeignKeyComposite && ! $assoc->isIndexed()) {
25992602
$this->scheduleCollectionForBatchLoading($pColl, $class);
26002603
} else {
26012604
$this->loadCollection($pColl);

tests/Tests/Models/EagerFetchedCompositeOneToMany/RootEntity.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,16 @@ class RootEntity
2424
#[ORM\OneToMany(mappedBy: 'root', targetEntity: SecondLevel::class, fetch: 'EAGER')]
2525
private Collection $secondLevel;
2626

27+
/** @var Collection<int, SecondLevelWithoutCompositePrimaryKey> */
28+
#[ORM\OneToMany(mappedBy: 'root', targetEntity: SecondLevelWithoutCompositePrimaryKey::class, fetch: 'EAGER')]
29+
private Collection $anotherSecondLevel;
30+
2731
public function __construct(int $id, string $other)
2832
{
29-
$this->otherKey = $other;
30-
$this->secondLevel = new ArrayCollection();
31-
$this->id = $id;
33+
$this->otherKey = $other;
34+
$this->secondLevel = new ArrayCollection();
35+
$this->anotherSecondLevel = new ArrayCollection();
36+
$this->id = $id;
3237
}
3338

3439
public function getId(): int|null
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
class SecondLevelWithoutCompositePrimaryKey
11+
{
12+
#[ORM\Id]
13+
#[ORM\GeneratedValue]
14+
#[ORM\Column(type: 'integer', nullable: false)]
15+
private int|null $id;
16+
17+
#[ORM\ManyToOne(targetEntity: RootEntity::class, inversedBy: 'anotherSecondLevel')]
18+
#[ORM\JoinColumn(name: 'root_id', referencedColumnName: 'id')]
19+
#[ORM\JoinColumn(name: 'root_other_key', referencedColumnName: 'other_key')]
20+
private RootEntity $root;
21+
22+
public function __construct(RootEntity $upper)
23+
{
24+
$this->root = $upper;
25+
}
26+
27+
public function getId(): int|null
28+
{
29+
return $this->id;
30+
}
31+
}

tests/Tests/ORM/Functional/EagerFetchOneToManyWithCompositeKeyTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Doctrine\Tests\Models\EagerFetchedCompositeOneToMany\RootEntity;
88
use Doctrine\Tests\Models\EagerFetchedCompositeOneToMany\SecondLevel;
9+
use Doctrine\Tests\Models\EagerFetchedCompositeOneToMany\SecondLevelWithoutCompositePrimaryKey;
910
use Doctrine\Tests\OrmFunctionalTestCase;
1011
use PHPUnit\Framework\Attributes\Group;
1112

@@ -14,7 +15,7 @@ final class EagerFetchOneToManyWithCompositeKeyTest extends OrmFunctionalTestCas
1415
#[Group('GH11154')]
1516
public function testItDoesNotThrowAnExceptionWhenTriggeringALoad(): void
1617
{
17-
$this->setUpEntitySchema([RootEntity::class, SecondLevel::class]);
18+
$this->setUpEntitySchema([RootEntity::class, SecondLevel::class, SecondLevelWithoutCompositePrimaryKey::class]);
1819

1920
$a1 = new RootEntity(1, 'A');
2021

0 commit comments

Comments
 (0)