Fix flush crash when deleting an inherited ManyToMany target (#105)#106
Merged
rcsofttech85 merged 1 commit intoJun 13, 2026
Merged
Conversation
…ech85#105) Deleting an entity that is the target of a ManyToMany association whose target class uses inheritance (JOINED/SINGLE_TABLE) crashed during EntityManager::flush() with: ResultSetMappingBuilder does not currently support your inheritance scheme. AssociationImpactAnalyzer::canReadCollectionThroughCriteria() returned true for any clean, uninitialized PersistentCollection, so resolveCollectionItems() / resolveCollectionIds() read the owner collection via matching(Criteria). Doctrine's ManyToManyPersister::loadCriteria() builds a ResultSetMapping via ResultSetMappingBuilder::addRootEntityFromClassMetadata(), which explicitly rejects inheritance schemes. Bail out of the Criteria fast-path when the association is ManyToMany and the target entity uses inheritance, falling back to the existing iteration / lazy loading path, which hydrates inherited entities correctly. Adds a functional regression test (Club -> ManyToMany -> inherited Membership) that crashes on flush without the fix. Fixes rcsofttech85#105 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 0 |
| Duplication | 0 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
Owner
|
Thank You @gdbonino |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #105.
Problem
Deleting an entity that is the target of a ManyToMany association whose target class uses class inheritance (
JOINED/SINGLE_TABLE) crashes duringEntityManager::flush():AssociationImpactAnalyzer::canReadCollectionThroughCriteria()returnstruefor any clean, uninitializedPersistentCollection, soresolveCollectionItems()/resolveCollectionIds()read the owner collection viamatching(Criteria::create()). Doctrine'sManyToManyPersister::loadCriteria()builds aResultSetMappingthroughResultSetMappingBuilder::addRootEntityFromClassMetadata(), which explicitly rejects inheritance schemes — a long-standing Doctrine limitation, so the bundle can't rely onmatching()for those associations.Fix
Skip the Criteria fast-path when the association is ManyToMany and the target entity uses inheritance, falling back to the existing iteration / lazy-loading path (which hydrates inherited entities correctly):
This is a behavior fix only — no public API change.
Test
Adds a functional regression test (
ManyToManyInheritanceDeleteTest) with a new fixture (Club→ ManyToMany → inheritedMembership/PremiumMembership,JOINED). It mirrors the existingCollectionInitializationSafetyTestdelete-impact scenario but with an inherited target: it deletes a membership while the owner collection is clean and uninitialized, and asserts the flush no longer crashes and the owner audit log records the5 → 4change. The test fails onmainwith the exactResultSetMappingBuildererror and passes with the fix.composer checkis green (921 tests, PHPStan, php-cs-fixer).