-
Notifications
You must be signed in to change notification settings - Fork 43
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
Improve how relationship URI segments are automatically calculated (e.g. to replace dash case with underscore) #220
Comments
You can set the uri name on a relationship, as described here: I.e.: HasMany::make('moduleNumbers')->withUriFieldName('module_numbers') |
FYI the reason for setting it on the relationship is because the URL part relates to the relationship name, not the resource type returned by that relationship. I.e. I could have a relationship called |
Yes, I see your point, but I think it's still a wrong or unexpected behaviour: using a "person" scheme for an editor or creator is one thing. But using a different naming way as the default value is something totally different. I don't want to add a method to all my relations, that could be derived from the name itself. Also it makes code a lot more erroneous. So: please re-open this issue and I will try to create a pull request for this topic. |
So to be clear this isn't a bug - it's perfectly possible to set whatever URI segments you want, either for the resource type, or for a relationship endpoint. Could how that is implemented be improved? Possibly. However, the thing to bear in mind is that to add some sort of calculation maybe reduces the dev effort of having to define it on relationships, but the "cost" of calculating it will be incurred on every single request. So there's a balancing act between saving the developer time and introducing repetitive calculations. My best guess would be somewhere for both the resource type URI segment, and the relationship URI segment, there's a call to dash-case the segment. If that's the case, then it could perhaps be overriden somehow so you can replace the dash-casing with underscores if wanted. |
Hej,
I tried to change the uri type of my schemas from being dasherized to use camel case. So far no big deal. But I noticed that this change is not reflected in the urls of related entities. Actually, this is what I expect to see when I change the
#uriType()
in a schema.I will further investigate this topic in the next days. This issue is only to keep a light on it. Maybe somebody else has noticed this: you're not alone with it!
As far as I have searched the url is build within
LaravelJsonApi\Core\Resources\Relation#relatedUrl()
. But I guess there has to be a change inLaravelJsonApi\Eloquent\Fields\Relations\Relation
.The text was updated successfully, but these errors were encountered: