File tree Expand file tree Collapse file tree 3 files changed +32
-0
lines changed Expand file tree Collapse file tree 3 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,12 @@ awareness about deprecated code.
88
99# Upgrade to 4.4
1010
11+ ## Deprecated overwriting foreign key constraints
12+
13+ Adding a foreign key constraint with a name that matches an existing one, whether explicitly specified or
14+ auto-generated, has been deprecated. In order to replace an existing constraint, drop it first
15+ via ` dropForeignKey() ` .
16+
1117## Deprecated ` View ` features
1218
1319The ` View ` constructor has been marked as internal. Use ` View::editor() ` to instantiate an editor and
Original file line number Diff line number Diff line change @@ -938,6 +938,14 @@ protected function _addForeignKeyConstraint(ForeignKeyConstraint $constraint): s
938938 );
939939
940940 $ name = $ this ->normalizeIdentifier ($ name );
941+ if (isset ($ this ->_fkConstraints [$ name ])) {
942+ Deprecation::trigger (
943+ 'doctrine/dbal ' ,
944+ 'https://github.com/doctrine/dbal/pull/7125 ' ,
945+ 'Overwriting an existing foreign key constraint ("%s") is deprecated. ' ,
946+ $ name ,
947+ );
948+ }
941949
942950 $ this ->_fkConstraints [$ name ] = $ constraint ;
943951
Original file line number Diff line number Diff line change @@ -1768,4 +1768,22 @@ public function testInvalidPrimaryKeyIndex(): void
17681768 $ this ->expectException (InvalidState::class);
17691769 $ table ->getPrimaryKeyConstraint ();
17701770 }
1771+
1772+ public function testOverwritingForeignKeyConstraint (): void
1773+ {
1774+ $ table = Table::editor ()
1775+ ->setUnquotedName ('foo ' )
1776+ ->setColumns (
1777+ Column::editor ()
1778+ ->setUnquotedName ('id ' )
1779+ ->setTypeName (Types::INTEGER )
1780+ ->create (),
1781+ )
1782+ ->create ();
1783+
1784+ $ table ->addForeignKeyConstraint ('bar ' , ['id ' ], ['id ' ]);
1785+
1786+ $ this ->expectDeprecationWithIdentifier ('https://github.com/doctrine/dbal/pull/7125 ' );
1787+ $ table ->addForeignKeyConstraint ('baz ' , ['id ' ], ['id ' ]);
1788+ }
17711789}
You can’t perform that action at this time.
0 commit comments