1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
|
<?php
declare(strict_types=1);
namespace Doctrine\Tests\ORM\Functional\Ticket;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\JoinColumn;
use Doctrine\ORM\Mapping\ManyToOne;
use Doctrine\ORM\Mapping\OneToOne;
use Doctrine\Tests\OrmFunctionalTestCase;
use PHPUnit\Framework\Attributes\Group;
#[Group('DDC-2575')]
class DDC2575Test extends OrmFunctionalTestCase
{
/** @phpstan-var list<DDC2575Root> */
private array $rootsEntities = [];
/** @phpstan-var list<DDC2575A> */
private array $aEntities = [];
/** @phpstan-var list<DDC2575B> */
private array $bEntities = [];
protected function setUp(): void
{
parent::setUp();
$this->createSchemaForModels(
DDC2575Root::class,
DDC2575A::class,
DDC2575B::class,
);
$entityRoot1 = new DDC2575Root(1);
$entityB1 = new DDC2575B(2);
$entityA1 = new DDC2575A($entityRoot1, $entityB1);
$this->_em->persist($entityRoot1);
$this->_em->persist($entityA1);
$this->_em->persist($entityB1);
$entityRoot2 = new DDC2575Root(3);
$entityB2 = new DDC2575B(4);
$entityA2 = new DDC2575A($entityRoot2, $entityB2);
$this->_em->persist($entityRoot2);
$this->_em->persist($entityA2);
$this->_em->persist($entityB2);
$this->_em->flush();
$this->rootsEntities[] = $entityRoot1;
$this->rootsEntities[] = $entityRoot2;
$this->aEntities[] = $entityA1;
$this->aEntities[] = $entityA2;
$this->bEntities[] = $entityB1;
$this->bEntities[] = $entityB2;
$this->_em->clear();
}
public function testHydrationIssue(): void
{
$repository = $this->_em->getRepository(DDC2575Root::class);
$qb = $repository->createQueryBuilder('r')
->select('r, a, b')
->leftJoin('r.aRelation', 'a')
->leftJoin('a.bRelation', 'b');
$query = $qb->getQuery();
$result = $query->getResult();
self::assertCount(2, $result);
$row = $result[0];
self::assertNotNull($row->aRelation);
self::assertEquals(1, $row->id);
self::assertNotNull($row->aRelation->rootRelation);
self::assertSame($row, $row->aRelation->rootRelation);
self::assertNotNull($row->aRelation->bRelation);
self::assertEquals(2, $row->aRelation->bRelation->id);
$row = $result[1];
self::assertNotNull($row->aRelation);
self::assertEquals(3, $row->id);
self::assertNotNull($row->aRelation->rootRelation);
self::assertSame($row, $row->aRelation->rootRelation);
self::assertNotNull($row->aRelation->bRelation);
self::assertEquals(4, $row->aRelation->bRelation->id);
}
}
#[Entity]
class DDC2575Root
{
/** @var DDC2575A */
#[OneToOne(targetEntity: 'DDC2575A', mappedBy: 'rootRelation')]
public $aRelation;
public function __construct(
#[Id]
#[Column(type: 'integer')]
public int $id,
#[Column(type: 'integer')]
public int $sampleField = 0,
) {
}
}
#[Entity]
class DDC2575A
{
public function __construct(
#[Id]
#[OneToOne(targetEntity: 'DDC2575Root', inversedBy: 'aRelation')]
#[JoinColumn(name: 'root_id', referencedColumnName: 'id', nullable: false, onDelete: 'CASCADE')]
public DDC2575Root $rootRelation,
#[ManyToOne(targetEntity: 'DDC2575B')]
#[JoinColumn(name: 'b_id', referencedColumnName: 'id', nullable: false, onDelete: 'CASCADE')]
public DDC2575B $bRelation,
) {
}
}
#[Entity]
class DDC2575B
{
public function __construct(
#[Id]
#[Column(type: 'integer')]
public int $id,
#[Column(type: 'integer')]
public int $sampleField = 0,
) {
}
}
|