|
11 | 11 | use Doctrine\ORM\Mapping\Id; |
12 | 12 | use Doctrine\ORM\Mapping\JoinColumn; |
13 | 13 | use Doctrine\ORM\Mapping\ManyToOne; |
| 14 | +use Doctrine\ORM\Mapping\OneToOne; |
14 | 15 | use Doctrine\ORM\Mapping\Table; |
15 | 16 | use Doctrine\Tests\OrmFunctionalTestCase; |
16 | 17 | use PHPUnit\Framework\Attributes\Group; |
@@ -42,6 +43,60 @@ public function testUpdateSchemaWithPostgreSQLSchema(): void |
42 | 43 |
|
43 | 44 | self::assertCount(0, $sql, implode("\n", $sql)); |
44 | 45 | } |
| 46 | + |
| 47 | + public function testUpdateSchemaWithJoinColumnWithOptions(): void |
| 48 | + { |
| 49 | + $sql = $this->getUpdateSchemaSqlForModels( |
| 50 | + TestEntityWithJoinColumnWithOptions::class, |
| 51 | + TestEntityWithJoinColumnWithOptionsRelation::class, |
| 52 | + ); |
| 53 | + |
| 54 | + $this->assertSame([ |
| 55 | + 'CREATE TABLE test (id INT NOT NULL, testRelation1_id INT DEFAULT NULL, testRelation2_id INT DEFAULT NULL, PRIMARY KEY(id))', |
| 56 | + 'CREATE UNIQUE INDEX UNIQ_D87F7E0C331521C6 ON test (testRelation1_id)', |
| 57 | + 'CREATE UNIQUE INDEX UNIQ_D87F7E0C21A08E28 ON test (testRelation2_id)', |
| 58 | + 'CREATE TABLE test_relation (id INT NOT NULL, PRIMARY KEY(id))', |
| 59 | + 'ALTER TABLE test ADD CONSTRAINT FK_D87F7E0C331521C6 FOREIGN KEY (testRelation1_id) REFERENCES test_relation (id) DEFERRABLE INITIALLY DEFERRED', |
| 60 | + 'ALTER TABLE test ADD CONSTRAINT FK_D87F7E0C21A08E28 FOREIGN KEY (testRelation2_id) REFERENCES test_relation (id) NOT DEFERRABLE INITIALLY IMMEDIATE', |
| 61 | + ], $sql); |
| 62 | + |
| 63 | + foreach ($sql as $query) { |
| 64 | + $this->_em->getConnection()->executeQuery($query); |
| 65 | + } |
| 66 | + |
| 67 | + $sql = $this->getUpdateSchemaSqlForModels( |
| 68 | + TestEntityWithJoinColumnWithOptions::class, |
| 69 | + TestEntityWithJoinColumnWithOptionsRelation::class, |
| 70 | + ); |
| 71 | + |
| 72 | + $this->assertSame([], $sql); |
| 73 | + } |
| 74 | +} |
| 75 | + |
| 76 | +#[Table('test')] |
| 77 | +#[Entity] |
| 78 | +class TestEntityWithJoinColumnWithOptions |
| 79 | +{ |
| 80 | + #[Id] |
| 81 | + #[Column] |
| 82 | + private int $id; |
| 83 | + |
| 84 | + #[OneToOne(targetEntity: TestEntityWithJoinColumnWithOptionsRelation::class)] |
| 85 | + #[JoinColumn(options: ['deferrable' => true, 'deferred' => true])] |
| 86 | + private TestEntityWithJoinColumnWithOptionsRelation $testRelation1; |
| 87 | + |
| 88 | + #[OneToOne(targetEntity: TestEntityWithJoinColumnWithOptionsRelation::class)] |
| 89 | + #[JoinColumn] |
| 90 | + private TestEntityWithJoinColumnWithOptionsRelation $testRelation2; |
| 91 | +} |
| 92 | + |
| 93 | +#[Table('test_relation')] |
| 94 | +#[Entity] |
| 95 | +class TestEntityWithJoinColumnWithOptionsRelation |
| 96 | +{ |
| 97 | + #[Id] |
| 98 | + #[Column] |
| 99 | + private int $id; |
45 | 100 | } |
46 | 101 |
|
47 | 102 | #[Table(name: 'stonewood.screen')] |
|
0 commit comments