Skip to content

Fix ORM 3 inverse-side mappings without inversedBy#1641

Open
alexmart wants to merge 1 commit intoergebnis:mainfrom
alexmart:fix/doctrine-orm3-inverse-side-inversedby
Open

Fix ORM 3 inverse-side mappings without inversedBy#1641
alexmart wants to merge 1 commit intoergebnis:mainfrom
alexmart:fix/doctrine-orm3-inverse-side-inversedby

Conversation

@alexmart
Copy link
Copy Markdown
Contributor

@alexmart alexmart commented Mar 17, 2026

Summary

When using Doctrine ORM 3, ClassMetadata::getAssociationMapping() can return mapping objects for inverse-side one-to-one associations (for example OneToOneInverseSideMapping) that do not expose an inversedBy property.

FixtureFactory::resolveInversedBy() currently accesses $association->inversedBy unconditionally for object mappings, which triggers a runtime error in this case.

What this changes

  • Return null when an association mapping object has no inversedBy property.
  • Keep existing behavior for array mappings and owning-side mappings.
  • Add a regression test that creates an entity with a single-valued inverse-side one-to-one association (Fingerprint::$device) to verify fixture creation does not fail.

Why this is safe

updateCollectionSideOfAssociation() already treats a non-string result from resolveInversedBy() as a no-op, so returning null cleanly skips back-reference updates where they are not applicable.

Verification

  • vendor/bin/phpunit --configuration=test/phpunit.xml --testsuite=unit
  • vendor/bin/phpunit --configuration=test/phpunit.xml --testsuite=integration
  • vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php --dry-run --diff

Doctrine ORM 3 returns mapping objects for inverse one-to-one associations that do not expose an inversedBy property. Accessing it triggers a runtime error.

Guard the property access and return null when inversedBy is unavailable so association updates are skipped safely.

Add a regression test with a single-valued inverse-side one-to-one association to prove fixture creation no longer fails.
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 17, 2026

Codecov Report

❌ Patch coverage is 66.66667% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 99.24%. Comparing base (f3614de) to head (59931b0).

Files with missing lines Patch % Lines
src/FixtureFactory.php 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##               main    #1641   +/-   ##
=========================================
  Coverage     99.23%   99.24%           
- Complexity      107      108    +1     
=========================================
  Files            28       28           
  Lines           393      395    +2     
=========================================
+ Hits            390      392    +2     
  Misses            3        3           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants