You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using self-referential relationships in CakePHP with the JSON API plugin, the route name generation fails because the registry alias is incorrectly set to the association name instead of the source table name.
Example
Given a People table with a self-referential relationship named Administratives:
// In PeopleTable.php$this->belongsToMany('Administratives', [
'className' => 'People',
// ... other options
]);
The plugin attempts to generate a route name using:
The registry alias becomes "Administratives" (the association name) instead of "People"
The resulting route "CrudJsonApi.Administratives:Administratives" doesn't exist
The correct route should be "CrudJsonApi.People:Administratives"
Current Behavior
Regular relationships work correctly (e.g., Enquiries -> People as Administratives)
Self-referential relationships fail with MissingRouteException
Expected Behavior
Both regular and self-referential relationships should generate correct route names using the controller name rather than the potentially confused registry alias.
Fix
Use the controller name from routing parameters instead of the registry alias:
_getRepositoryRoutingParameters() returns the correct controller name regardless of relationship type
For regular relationships, it produces the same result as before
For self-referential relationships, it fixes the registry alias confusion
It respects plugin prefixes and custom resource paths
Additional Context
This issue only affects self-referential relationships where the association name differs from the table name. The fix maintains compatibility with all other relationship types while correctly handling the self-referential case.
The text was updated successfully, but these errors were encountered:
Description
When using self-referential relationships in CakePHP with the JSON API plugin, the route name generation fails because the registry alias is incorrectly set to the association name instead of the source table name.
Example
Given a
People
table with a self-referential relationship namedAdministratives
:The plugin attempts to generate a route name using:
This fails because:
Current Behavior
MissingRouteException
Expected Behavior
Both regular and self-referential relationships should generate correct route names using the controller name rather than the potentially confused registry alias.
Fix
Use the controller name from routing parameters instead of the registry alias:
This works because:
_getRepositoryRoutingParameters()
returns the correct controller name regardless of relationship typeAdditional Context
This issue only affects self-referential relationships where the association name differs from the table name. The fix maintains compatibility with all other relationship types while correctly handling the self-referential case.
The text was updated successfully, but these errors were encountered: