|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Doctrine\Tests\ORM\Functional\Ticket; |
| 6 | + |
| 7 | +use Doctrine\Common\Collections\Collection; |
| 8 | +use Doctrine\ORM\Mapping\Column; |
| 9 | +use Doctrine\ORM\Mapping\DiscriminatorMap; |
| 10 | +use Doctrine\ORM\Mapping\Entity; |
| 11 | +use Doctrine\ORM\Mapping\GeneratedValue; |
| 12 | +use Doctrine\ORM\Mapping\Id; |
| 13 | +use Doctrine\ORM\Mapping\InheritanceType; |
| 14 | +use Doctrine\ORM\Mapping\ManyToOne; |
| 15 | +use Doctrine\ORM\Mapping\OneToMany; |
| 16 | +use Doctrine\Tests\OrmFunctionalTestCase; |
| 17 | + |
| 18 | +class GH7512Test extends OrmFunctionalTestCase |
| 19 | +{ |
| 20 | + protected function setUp(): void |
| 21 | + { |
| 22 | + parent::setUp(); |
| 23 | + |
| 24 | + $this->setUpEntitySchema([ |
| 25 | + GH7512EntityA::class, |
| 26 | + GH7512EntityB::class, |
| 27 | + GH7512EntityC::class, |
| 28 | + ]); |
| 29 | + |
| 30 | + $this->_em->persist(new GH7512EntityA()); |
| 31 | + $this->_em->persist(new GH7512EntityC()); |
| 32 | + $this->_em->flush(); |
| 33 | + $this->_em->clear(); |
| 34 | + } |
| 35 | + |
| 36 | + public function testFindEntityByAssociationPropertyJoinedChildWithClearMetadata(): void |
| 37 | + { |
| 38 | + // unset metadata for entity B as though it hasn't been touched yet in application lifecycle. |
| 39 | + $this->_em->getMetadataFactory()->setMetadataFor(GH7512EntityB::class, null); |
| 40 | + $result = $this->_em->getRepository(GH7512EntityC::class)->findBy([ |
| 41 | + 'entityA' => new GH7512EntityB(), |
| 42 | + ]); |
| 43 | + $this->assertEmpty($result); |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +/** |
| 48 | + * @Entity() |
| 49 | + * @InheritanceType("JOINED") |
| 50 | + * @DiscriminatorMap({ |
| 51 | + * "entitya"=Doctrine\Tests\ORM\Functional\Ticket\GH7512EntityA::class, |
| 52 | + * "entityB"=Doctrine\Tests\ORM\Functional\Ticket\GH7512EntityB::class |
| 53 | + * }) |
| 54 | + */ |
| 55 | +class GH7512EntityA |
| 56 | +{ |
| 57 | + /** |
| 58 | + * @Column(type="integer") |
| 59 | + * @Id() |
| 60 | + * @GeneratedValue(strategy="AUTO") |
| 61 | + * @var int |
| 62 | + */ |
| 63 | + public $id; |
| 64 | + |
| 65 | + /** |
| 66 | + * @OneToMany(targetEntity="Doctrine\Tests\ORM\Functional\Ticket\GH7512EntityC", mappedBy="entityA") |
| 67 | + * @var Collection<int, GH7512EntityC> |
| 68 | + */ |
| 69 | + public $entityCs; |
| 70 | +} |
| 71 | + |
| 72 | +/** |
| 73 | + * @Entity() |
| 74 | + */ |
| 75 | +class GH7512EntityB extends GH7512EntityA |
| 76 | +{ |
| 77 | +} |
| 78 | + |
| 79 | +/** |
| 80 | + * @Entity() |
| 81 | + */ |
| 82 | +class GH7512EntityC |
| 83 | +{ |
| 84 | + /** |
| 85 | + * @Column(type="integer") |
| 86 | + * @Id() |
| 87 | + * @GeneratedValue(strategy="AUTO") |
| 88 | + * @var int |
| 89 | + */ |
| 90 | + public $id; |
| 91 | + |
| 92 | + /** |
| 93 | + * @ManyToOne(targetEntity="Doctrine\Tests\ORM\Functional\Ticket\GH7512EntityA", inversedBy="entityCs") |
| 94 | + * @var GH7512EntityA |
| 95 | + */ |
| 96 | + public $entityA; |
| 97 | +} |
0 commit comments