Skip to content

Add regression test for STI duplicate foreign key deduplication - #12391

Open
janedbal wants to merge 1 commit into
doctrine:3.6.xfrom
janedbal:fix/sti-duplicate-foreign-key-deprecation
Open

Add regression test for STI duplicate foreign key deduplication#12391
janedbal wants to merge 1 commit into
doctrine:3.6.xfrom
janedbal:fix/sti-duplicate-foreign-key-deprecation

Conversation

@janedbal

@janedbal janedbal commented Mar 10, 2026

Copy link
Copy Markdown
Contributor

When multiple STI child entities have a ManyToOne relation to the same target entity using the same join column, SchemaTool called addForeignKeyConstraint twice with the same constraint name, triggering a DBAL deprecation ("Overwriting an existing foreign key constraint").

The fix skips the redundant addForeignKeyConstraint call when an identical FK (same local columns, same foreign table, same foreign columns) was already added.

See doctrine/dbal#7125


EDIT (after rebase): The production fix has since landed in 3.6.x via #12477 ("Avoid adding the same foreign key twice for STI"), which implements the same deduplication more thoroughly (it also compares FK options). Rebasing dropped the now-redundant SchemaTool change, so this PR now only adds the regression test — upstream merged the fix without one, and this test guards the STI same-join-column scenario going forward.

@janedbal

Copy link
Copy Markdown
Contributor Author

Any chance somebody looks into this one?

@greg0ire

Copy link
Copy Markdown
Member

It seems there are CI jobs failing. Please take a look at this guide for more on how to handle those.

@janedbal
janedbal force-pushed the fix/sti-duplicate-foreign-key-deprecation branch from f750132 to 9a912d2 Compare April 22, 2026 07:00
@janedbal

Copy link
Copy Markdown
Contributor Author

@greg0ire None of those were related to our changes. I just rebased to trigger new pipeline.

@greg0ire

Copy link
Copy Markdown
Member

That's cool. Bear in mind that I will always prioritize reviewing PRs with a green build.

Comment thread tests/Tests/ORM/Tools/SchemaToolTest.php
@janedbal
janedbal requested a review from greg0ire July 10, 2026 07:47
When multiple STI child entities have a ManyToOne relation to the same
target entity using the same join column, SchemaTool used to call
addForeignKeyConstraint twice with the same constraint name, triggering
a DBAL deprecation ("Overwriting an existing foreign key constraint").

The production fix landed in 3.6.x via doctrine#12477 ("Avoid adding the same
foreign key twice for STI") but shipped without a regression test. This
adds the missing coverage: the STI table must end up with exactly one
foreign key when children share the same join column.

See doctrine/dbal#7125
@janedbal
janedbal force-pushed the fix/sti-duplicate-foreign-key-deprecation branch from 451f52b to d9b04de Compare July 10, 2026 07:55
@janedbal janedbal changed the title Fix duplicate foreign key deprecation with Single Table Inheritance Add regression test for STI duplicate foreign key deduplication Jul 10, 2026
return false;
}

public function testSingleTableInheritanceWithSameForeignKeyInChildrenDoesNotTriggerDeprecation(): void

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants