|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Doctrine\Tests\ORM\Functional; |
| 6 | + |
| 7 | +use Doctrine\Tests\Models\OneToOneInverseSideWithAssociativeIdLoad\InverseSide; |
| 8 | +use Doctrine\Tests\Models\OneToOneInverseSideWithAssociativeIdLoad\InverseSideIdTarget; |
| 9 | +use Doctrine\Tests\Models\OneToOneInverseSideWithAssociativeIdLoad\OwningSide; |
| 10 | +use Doctrine\Tests\OrmFunctionalTestCase; |
| 11 | + |
| 12 | +use function assert; |
| 13 | + |
| 14 | +class OneToOneInverseSideWithAssociativeIdLoadAfterDqlQueryTest extends OrmFunctionalTestCase |
| 15 | +{ |
| 16 | + protected function setUp(): void |
| 17 | + { |
| 18 | + parent::setUp(); |
| 19 | + |
| 20 | + $this->createSchemaForModels(OwningSide::class, InverseSideIdTarget::class, InverseSide::class); |
| 21 | + } |
| 22 | + |
| 23 | + /** @group GH-11108 */ |
| 24 | + public function testInverseSideWithAssociativeIdOneToOneLoadedAfterDqlQuery(): void |
| 25 | + { |
| 26 | + $owner = new OwningSide(); |
| 27 | + $inverseId = new InverseSideIdTarget(); |
| 28 | + $inverse = new InverseSide(); |
| 29 | + |
| 30 | + $owner->id = 'owner'; |
| 31 | + $inverseId->id = 'inverseId'; |
| 32 | + $inverseId->inverseSide = $inverse; |
| 33 | + $inverse->associativeId = $inverseId; |
| 34 | + $owner->inverse = $inverse; |
| 35 | + $inverse->owning = $owner; |
| 36 | + |
| 37 | + $this->_em->persist($owner); |
| 38 | + $this->_em->persist($inverseId); |
| 39 | + $this->_em->persist($inverse); |
| 40 | + $this->_em->flush(); |
| 41 | + $this->_em->clear(); |
| 42 | + |
| 43 | + $fetchedInverse = $this |
| 44 | + ->_em |
| 45 | + ->createQueryBuilder() |
| 46 | + ->select('inverse') |
| 47 | + ->from(InverseSide::class, 'inverse') |
| 48 | + ->andWhere('inverse.associativeId = :associativeId') |
| 49 | + ->setParameter('associativeId', 'inverseId') |
| 50 | + ->getQuery() |
| 51 | + ->getSingleResult(); |
| 52 | + assert($fetchedInverse instanceof InverseSide); |
| 53 | + |
| 54 | + self::assertInstanceOf(InverseSide::class, $fetchedInverse); |
| 55 | + self::assertInstanceOf(InverseSideIdTarget::class, $fetchedInverse->associativeId); |
| 56 | + self::assertInstanceOf(OwningSide::class, $fetchedInverse->owning); |
| 57 | + |
| 58 | + $this->assertSQLEquals( |
| 59 | + 'select o0_.associativeid as associativeid_0 from one_to_one_inverse_side_assoc_id_load_inverse o0_ where o0_.associativeid = ?', |
| 60 | + $this->getLastLoggedQuery(1)['sql'] |
| 61 | + ); |
| 62 | + |
| 63 | + $this->assertSQLEquals( |
| 64 | + 'select t0.id as id_1, t0.inverse as inverse_2 from one_to_one_inverse_side_assoc_id_load_owning t0 where t0.inverse = ?', |
| 65 | + $this->getLastLoggedQuery()['sql'] |
| 66 | + ); |
| 67 | + } |
| 68 | +} |
0 commit comments