-
Notifications
You must be signed in to change notification settings - Fork 109
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
Include related resources #23
Comments
Hi! Where are you getting the bottleneck problem... when encoding the model to JSON API (i.e. via the schema) or when processing something a client has sent you? The If you can give me some more information I can definitely help find a better solution. |
Hi! So writing your own What you want to do is use eager loading, which is an Eloquent feature: E.g. in the JSON API search class for that model: protected function filter(Builder $builder, Collection $filters)
{
$builder->with('transactions');
} You should see that |
👍 I missed that feature :) Thanks! |
No problem. |
Hi! Sorry to disturb you again. Next issue I have here - what about related resources? We having a pattern here with |
I haven't implemented full related resources support yet - it'll come in a future version. However, you can do this for the moment. In your $model = $this->getRecord($request);
$key = $this->keyForRelationship($request->getRelationshipName());
if ('comments' === $key) {
$content = $model->comments()->with('...')->get();
} else {
$content = $model->{$key};
}
return $this
->reply()
->content($content); I think you might already be overloading this method according to this issue: So you just need to add the |
Leave this issue open as I've tagged it with |
Relationships are now better supported on the |
With is now fully supported, including on relationships, in the 1.0 branch |
Our app have a fair amount of hasMany relationsships - and we are including them in our json-api responses - resulting eg. 5 queries pr. entity; and with 200 entities we have a bottleneck.
I were thinking about overwrite the EloquentAdapter#find method and do my own service-provide to register with my own class.
But is it the best way to handle it? It seems as a generic problem, and a standardized way of handling relationships.
The text was updated successfully, but these errors were encountered: