|
17 | 17 | use Doctrine\DBAL\Types\Types; |
18 | 18 | use Doctrine\ORM\Mapping\ClassMetadata; |
19 | 19 | use Doctrine\ORM\Mapping\Column; |
| 20 | +use Doctrine\ORM\Mapping\DiscriminatorColumn; |
| 21 | +use Doctrine\ORM\Mapping\DiscriminatorMap; |
20 | 22 | use Doctrine\ORM\Mapping\Entity; |
| 23 | +use Doctrine\ORM\Mapping\GeneratedValue; |
21 | 24 | use Doctrine\ORM\Mapping\Id; |
22 | 25 | use Doctrine\ORM\Mapping\Index; |
| 26 | +use Doctrine\ORM\Mapping\InheritanceType; |
23 | 27 | use Doctrine\ORM\Mapping\JoinColumn; |
24 | 28 | use Doctrine\ORM\Mapping\ManyToOne; |
25 | 29 | use Doctrine\ORM\Mapping\MappingException; |
@@ -523,6 +527,39 @@ private static function columnIsIndexed(DbalTable $table, string $column): bool |
523 | 527 |
|
524 | 528 | return false; |
525 | 529 | } |
| 530 | + |
| 531 | + public function testSingleTableInheritanceWithSameForeignKeyInChildrenDoesNotTriggerDeprecation(): void |
| 532 | + { |
| 533 | + $em = $this->getTestEntityManager(); |
| 534 | + $schemaTool = new SchemaTool($em); |
| 535 | + |
| 536 | + $schema = $schemaTool->getSchemaFromMetadata([ |
| 537 | + $em->getClassMetadata(STIBox::class), |
| 538 | + $em->getClassMetadata(STILocation::class), |
| 539 | + $em->getClassMetadata(STIBoxContainer::class), |
| 540 | + $em->getClassMetadata(STIPackedBoxContainer::class), |
| 541 | + ]); |
| 542 | + |
| 543 | + self::assertTrue($schema->hasTable('sti_location')); |
| 544 | + |
| 545 | + $table = $schema->getTable('sti_location'); |
| 546 | + |
| 547 | + self::assertCount(1, $table->getForeignKeys()); |
| 548 | + |
| 549 | + $foreignKeys = $table->getForeignKeys(); |
| 550 | + $foreignKey = current($foreignKeys); |
| 551 | + |
| 552 | + if (class_exists(ForeignKeyConstraintEditor::class)) { |
| 553 | + self::assertSame('sti_box', $foreignKey->getReferencedTableName()->toString()); |
| 554 | + self::assertSame(['box_id'], array_map( |
| 555 | + static fn (UnqualifiedName $name) => $name->toString(), |
| 556 | + $foreignKey->getReferencingColumnNames(), |
| 557 | + )); |
| 558 | + } else { |
| 559 | + self::assertSame('sti_box', $foreignKey->getForeignTableName()); |
| 560 | + self::assertSame(['box_id'], $foreignKey->getLocalColumns()); |
| 561 | + } |
| 562 | + } |
526 | 563 | } |
527 | 564 |
|
528 | 565 | #[Table(options: ['foo' => 'bar', 'baz' => ['key' => 'val']])] |
@@ -758,3 +795,42 @@ class QuotedEntity |
758 | 795 | #[Column(name: '`quoted-name`')] |
759 | 796 | public string $name = ''; |
760 | 797 | } |
| 798 | + |
| 799 | +#[Entity] |
| 800 | +#[Table(name: 'sti_box')] |
| 801 | +class STIBox |
| 802 | +{ |
| 803 | + #[Id] |
| 804 | + #[Column(type: 'integer')] |
| 805 | + #[GeneratedValue] |
| 806 | + public int|null $id = null; |
| 807 | +} |
| 808 | + |
| 809 | +#[Entity] |
| 810 | +#[Table(name: 'sti_location')] |
| 811 | +#[InheritanceType('SINGLE_TABLE')] |
| 812 | +#[DiscriminatorColumn(name: 'type', type: 'string')] |
| 813 | +#[DiscriminatorMap(['box_container' => STIBoxContainer::class, 'packed_box_container' => STIPackedBoxContainer::class])] |
| 814 | +abstract class STILocation |
| 815 | +{ |
| 816 | + #[Id] |
| 817 | + #[Column(type: 'integer')] |
| 818 | + #[GeneratedValue] |
| 819 | + public int|null $id = null; |
| 820 | +} |
| 821 | + |
| 822 | +#[Entity] |
| 823 | +class STIBoxContainer extends STILocation |
| 824 | +{ |
| 825 | + #[ManyToOne(targetEntity: STIBox::class)] |
| 826 | + #[JoinColumn(name: 'box_id', referencedColumnName: 'id')] |
| 827 | + public STIBox|null $box = null; |
| 828 | +} |
| 829 | + |
| 830 | +#[Entity] |
| 831 | +class STIPackedBoxContainer extends STILocation |
| 832 | +{ |
| 833 | + #[ManyToOne(targetEntity: STIBox::class)] |
| 834 | + #[JoinColumn(name: 'box_id', referencedColumnName: 'id')] |
| 835 | + public STIBox|null $box = null; |
| 836 | +} |
0 commit comments