-
Notifications
You must be signed in to change notification settings - Fork 45
How to get the related model in controller relationship hooks? #110
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
Comments
Hmm yeah I can see how that's confusing. The I can see how this is confusing though in relationship methods... given your example, I don't think the At this point in the request the status that is the other side of the relationship has not yet been loaded. So to get it, you'd need to do: $status = Status::find($data['status']['id']); Assuming that The difference between request and query... The request relates to the JSON:API resource that is in the request JSON. In this case, the request JSON is the content of the user's The query relates to the JSON:API query parameters - which affect the JSON:API resources in the response that the server will send. In this case, a |
I'm going to label this as a bug because it shows I need to remove the |
I could also potentially add a |
thanks, so, the query will only be used when sending the response back, it seems. However, I have a follow up question $this->relation('status')->withoutLinks() ) RelationshipResponse::make($user,$fieldName,$result)->withQueryParameters($query) it was not able to encode the response: error: the status relationship does not have a self link. of course it works after removing the DataResponse::make($user)->withQueryParameters($query); it works fine regardless of the withoutLinks presence. |
The Not sure why you're doing |
actually on the route definitions I didn't put them, I only need the update route $server->resource('users')
->relationships(function (Relationships $r) {
$r->hasOne('status')->only('update');
}) and I show it directly on the relation as a meta: public function relationships($request): iterable {
return [
$this->relation('status')->withoutLinks()->withMeta([
'name' => $this->status->name,
]),
];
} |
Hmmm yeah so the work-around for the moment will be to return a |
See #111 for the bug about the relationship links. |
I've dealt with the relationship links problem as part of #111. So to summarise here what I need to do with the original problem reported by this issue:
|
Turns out I can't remove the |
OK, have fixed by making |
I still need to add the method for access the inverse model or models on a relationship - my current thinking is I'll make those available via a |
The model and modelOrFail methods were never meant to be used publicly on the resource query class - and were not documented as a result. To prevent them being used on this class (as it is confusing as to which model is returned), these methods are now public on the resource request, and protected on the query request. See #110
This will be in |
I would expect $status to be the status model, but the variable contains the $user model instead
Also, if u can explain what is the difference between the $request and the $query
The text was updated successfully, but these errors were encountered: