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