Skip to content

Commit b4bb7fc

Browse files
committed
add test
1 parent 08da174 commit b4bb7fc

File tree

3 files changed

+56
-4
lines changed

3 files changed

+56
-4
lines changed

tests/Tests/Models/EagerFetchedCompositeOneToMany/RootEntity.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,19 @@ class RootEntity
3737
*/
3838
private $secondLevel;
3939

40+
/**
41+
* @ORM\OneToMany(mappedBy="root", targetEntity=SecondLevelWithoutCompositePrimaryKey::class, fetch="EAGER")
42+
*
43+
* @var Collection<int, SecondLevelWithoutCompositePrimaryKey>
44+
*/
45+
private $anotherSecondLevel;
46+
4047
public function __construct(int $id, string $other)
4148
{
42-
$this->otherKey = $other;
43-
$this->secondLevel = new ArrayCollection();
44-
$this->id = $id;
49+
$this->otherKey = $other;
50+
$this->secondLevel = new ArrayCollection();
51+
$this->anotherSecondLevel = new ArrayCollection();
52+
$this->id = $id;
4553
}
4654

4755
public function getId(): ?int
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\ORM\Mapping as ORM;
8+
9+
/**
10+
* @ORM\Entity
11+
*/
12+
class SecondLevelWithoutCompositePrimaryKey
13+
{
14+
/**
15+
* @ORM\Id
16+
* @ORM\GeneratedValue
17+
* @ORM\Column(type="integer", nullable=false)
18+
*
19+
* @var int|null
20+
*/
21+
private $id;
22+
23+
/**
24+
* @ORM\ManyToOne(targetEntity=RootEntity::class, inversedBy="anotherSecondLevel")
25+
* @ORM\JoinColumns({
26+
* @ORM\JoinColumn(name="root_id", referencedColumnName="id"),
27+
* @ORM\JoinColumn(name="root_other_key", referencedColumnName="other_key")
28+
* })
29+
*
30+
* @var RootEntity
31+
*/
32+
private $root;
33+
34+
public function __construct(RootEntity $upper)
35+
{
36+
$this->root = $upper;
37+
}
38+
39+
public function getId(): ?int
40+
{
41+
return $this->id;
42+
}
43+
}

tests/Tests/ORM/Functional/EagerFetchOneToManyWithCompositeKeyTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
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

1112
final class EagerFetchOneToManyWithCompositeKeyTest extends OrmFunctionalTestCase
1213
{
1314
/** @ticket 11154 */
1415
public function testItDoesNotThrowAnExceptionWhenTriggeringALoad(): void
1516
{
16-
$this->setUpEntitySchema([RootEntity::class, SecondLevel::class]);
17+
$this->setUpEntitySchema([RootEntity::class, SecondLevel::class, SecondLevelWithoutCompositePrimaryKey::class]);
1718

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

0 commit comments

Comments
 (0)