Fix OperationResponseAssociation ignoring controller defaultTable#582
Merged
cnizzardini merged 6 commits intocnizzardini:masterfrom Apr 22, 2026
Conversation
When associations['table'] is not explicitly set, OperationResponseAssociation::build() now resolves the table via the controller's fetchTable() method, which respects $defaultTable, before falling back to the controller name. This aligns with the pattern already used in ModelScanner::routeHasModel().
ba2aeef to
64272f3
Compare
ReflectionProperty::setAccessible() has no effect since PHP 8.1 and is deprecated in PHP 8.5.
Moves the controller fetchTable logic into a protected method, reducing cyclomatic and NPath complexity in build() and making the table resolution mockable in tests.
Contributor
Author
|
@cnizzardini can you take a look when you get a chance and lmk if you like this fix? In our application code, we are able to get by with setting the 'table' key of the |
cnizzardini
reviewed
Apr 21, 2026
cnizzardini
reviewed
Apr 21, 2026
Owner
|
Just a few comments @jamisonbryant but this looks like a good change! Surprised this went unnoticed for so long, pretty sure this has been in there since day 1. I'll pull this down as soon as I can and do some quick testing. |
Contributor
Author
|
btw really like the phpmd integration, loved how it yelled at me when I crossed the complexity threshold ❤️ |
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.
Summary
OperationResponseAssociation::build()ignores a controller's$defaultTableproperty when resolving the database table for associations. This causes aDatabaseExceptionwhen a controller name doesn't match its actual database table (e.g.,MyCoolFeatureControllerthat manages data from thefoobars_unrelatedtable viaprotected string $defaultTable = 'FoobarsUnrelated').The fix resolves the table via the controller's
fetchTable()method (which respects$defaultTable) before falling back to the controller name. This aligns with the pattern already used inModelScanner::routeHasModel().Major Changes
protected resolveTableAlias()method toOperationResponseAssociationthat resolves the table alias from the controller'sfetchTable(), falling back to the controller name. Extracted frombuild()to stay under the cyclomatic/NPath complexity thresholds and to provide a mockable seam for tests.ReflectionProperty::setAccessible()call inExceptionResponse(no-op since PHP 8.1, deprecated in 8.5).Minor Changes
CustomTableControllertest fixture with$defaultTable = 'Employees'to simulate a controller whose name doesn't match its tabletest_default_table_property_is_respectedtest case// TODOcomment from test setUpThrowableimport)Test Plan
fetchTable())$defaultTableset to a different table correctly resolves that table in the association buildersetAccessible()