|
18 | 18 | use Doctrine\DBAL\Types\Types; |
19 | 19 | use Doctrine\ORM\Mapping\ClassMetadata; |
20 | 20 | use Doctrine\ORM\Mapping\Column; |
| 21 | +use Doctrine\ORM\Mapping\DiscriminatorColumn; |
| 22 | +use Doctrine\ORM\Mapping\DiscriminatorMap; |
21 | 23 | use Doctrine\ORM\Mapping\Entity; |
| 24 | +use Doctrine\ORM\Mapping\GeneratedValue; |
22 | 25 | use Doctrine\ORM\Mapping\Id; |
23 | 26 | use Doctrine\ORM\Mapping\Index; |
| 27 | +use Doctrine\ORM\Mapping\InheritanceType; |
24 | 28 | use Doctrine\ORM\Mapping\JoinColumn; |
25 | 29 | use Doctrine\ORM\Mapping\ManyToOne; |
26 | 30 | use Doctrine\ORM\Mapping\MappingException; |
@@ -581,6 +585,41 @@ private static function columnIsIndexed(DbalTable $table, string $column): bool |
581 | 585 |
|
582 | 586 | return false; |
583 | 587 | } |
| 588 | + |
| 589 | + public function testSingleTableInheritanceWithSameForeignKeyInChildrenDoesNotTriggerDeprecation(): void |
| 590 | + { |
| 591 | + $em = $this->getTestEntityManager(); |
| 592 | + $schemaTool = new SchemaTool($em); |
| 593 | + |
| 594 | + $schema = $schemaTool->getSchemaFromMetadata([ |
| 595 | + $em->getClassMetadata(STIBox::class), |
| 596 | + $em->getClassMetadata(STILocation::class), |
| 597 | + $em->getClassMetadata(STIBoxContainer::class), |
| 598 | + $em->getClassMetadata(STIPackedBoxContainer::class), |
| 599 | + ]); |
| 600 | + |
| 601 | + self::assertTrue($schema->hasTable('sti_location')); |
| 602 | + |
| 603 | + $table = $schema->getTable('sti_location'); |
| 604 | + |
| 605 | + self::assertCount(1, $table->getForeignKeys()); |
| 606 | + |
| 607 | + $foreignKeys = $table->getForeignKeys(); |
| 608 | + $foreignKey = current($foreignKeys); |
| 609 | + |
| 610 | + if (! class_exists(ForeignKeyConstraintEditor::class)) { |
| 611 | + self::assertSame('sti_box', $foreignKey->getForeignTableName()); |
| 612 | + self::assertSame(['box_id'], $foreignKey->getLocalColumns()); |
| 613 | + |
| 614 | + return; |
| 615 | + } |
| 616 | + |
| 617 | + self::assertSame('sti_box', $foreignKey->getReferencedTableName()->toString()); |
| 618 | + self::assertSame(['box_id'], array_map( |
| 619 | + static fn (UnqualifiedName $name) => $name->toString(), |
| 620 | + $foreignKey->getReferencingColumnNames(), |
| 621 | + )); |
| 622 | + } |
584 | 623 | } |
585 | 624 |
|
586 | 625 | #[Table(options: ['foo' => 'bar', 'baz' => ['key' => 'val']])] |
@@ -816,3 +855,42 @@ class QuotedEntity |
816 | 855 | #[Column(name: '`quoted-name`')] |
817 | 856 | public string $name = ''; |
818 | 857 | } |
| 858 | + |
| 859 | +#[Entity] |
| 860 | +#[Table(name: 'sti_box')] |
| 861 | +class STIBox |
| 862 | +{ |
| 863 | + #[Id] |
| 864 | + #[Column(type: 'integer')] |
| 865 | + #[GeneratedValue] |
| 866 | + public int|null $id = null; |
| 867 | +} |
| 868 | + |
| 869 | +#[Entity] |
| 870 | +#[Table(name: 'sti_location')] |
| 871 | +#[InheritanceType('SINGLE_TABLE')] |
| 872 | +#[DiscriminatorColumn(name: 'type', type: 'string')] |
| 873 | +#[DiscriminatorMap(['box_container' => STIBoxContainer::class, 'packed_box_container' => STIPackedBoxContainer::class])] |
| 874 | +abstract class STILocation |
| 875 | +{ |
| 876 | + #[Id] |
| 877 | + #[Column(type: 'integer')] |
| 878 | + #[GeneratedValue] |
| 879 | + public int|null $id = null; |
| 880 | +} |
| 881 | + |
| 882 | +#[Entity] |
| 883 | +class STIBoxContainer extends STILocation |
| 884 | +{ |
| 885 | + #[ManyToOne(targetEntity: STIBox::class)] |
| 886 | + #[JoinColumn(name: 'box_id', referencedColumnName: 'id')] |
| 887 | + public STIBox|null $box = null; |
| 888 | +} |
| 889 | + |
| 890 | +#[Entity] |
| 891 | +class STIPackedBoxContainer extends STILocation |
| 892 | +{ |
| 893 | + #[ManyToOne(targetEntity: STIBox::class)] |
| 894 | + #[JoinColumn(name: 'box_id', referencedColumnName: 'id')] |
| 895 | + public STIBox|null $box = null; |
| 896 | +} |
0 commit comments