Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Q] Shouldn't be 'index' the route name for the listing action of a HasMany relationship? #233

Open
nelson6e65 opened this issue Apr 11, 2023 · 7 comments

Comments

@nelson6e65
Copy link

nelson6e65 commented Apr 11, 2023

I have in my route:

# routes/api.php
$server
  ->resource('users', JsonApiController::class)
  ->relationships(function (Relationships $relations) {
      $relations->hasMany('user-organizations');
  });
# UserSchema.php
public function fields(): array
{
    return [
        // ...
        Relations\HasMany::make('user-organizations')->type('user-organizations'),
    ];
}

But the resulting route name is api.v1.users.user-organizations instead of api.v1.users.user-organizations.index:

 GET|HEAD  api/v1/users/{user}/relationships/user-organizations ... api.v1.users.user-organizations.show
 PATCH     api/v1/users/{user}/relationships/user-organizations ... api.v1.users.user-organizations.update
 POST      api/v1/users/{user}/relationships/user-organizations ... api.v1.users.user-organizations.attach
 DELETE    api/v1/users/{user}/relationships/user-organizations ... api.v1.users.user-organizations.detach
 GET|HEAD  api/v1/users/{user}/user-organizations ................. api.v1.users.user-organizations

Am I missing something, or it's OK?

How can I change it to have 'index' by default in all routes of this kind, instead of the "naked" route action?

@lindyhopchris
Copy link
Contributor

It's been that way for a long time now, no one has ever raised it! Not sure it causes any problems?

@nelson6e65
Copy link
Author

nelson6e65 commented Apr 12, 2023

I noticed because I get an error from my route() function in my front. It builds the endpoint URL by using the route name instead of the route path directly.

@nelson6e65
Copy link
Author

nelson6e65 commented Apr 12, 2023

I was automating/normalizing my http client in my Vue application and got confused when I got this inconsistency. 😅

@lindyhopchris
Copy link
Contributor

Yeah sure, this could be tidied up. It'd need to be a major version release though, as it's potentially breaking if someone else is doing something along the lines of what you're doing with the route names.

@nelson6e65
Copy link
Author

x.x Yes, it's a potential breaking change.

But, it can be added a non-breaking (temporal) config option to replace this name, keeping the current value as default, so it will not be a BC and a normal feature release can be made, instead of a mayor release.

@lindyhopchris
Copy link
Contributor

I'm planning to do a major release the next time I do work on this package (probably mid-May onwards), so will just include it in that.

@nelson6e65
Copy link
Author

#238

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

No branches or pull requests

2 participants