Skip to content

Include relationship object in every response (even when omitted from include) #40

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

Open
nemanja-tosic opened this issue Dec 18, 2017 · 1 comment

Comments

@nemanja-tosic
Copy link

Hello, I have an issue with how the relationship objects are implemented. In order to prevent fetching of the same things over and over, i have some global dependencies that are fetched on app load. I store them (via redux in JS, because they are nice and normalized), and afterwards connect them with the object by using the ids. The way that the library is implemented prevents me from doing this. I can see that it was done to speed things up, but there is really no cost of adding the relationship objects as that data is already in the table, i just need the id.

Is this something that can be changed?

@tuyakhov
Copy link
Owner

Hi @nemanja-tosic

According to JSON API specification, the main use of data member in relationship object is to provide resource linkage in compound documents so you can link the resources within a single JSON document.
Therefore linking the resources between different API calls might lead to data inconsistency (some of the related resources might be deleted in between).

The other downside of your proposition is performance. It is recommended to include all available relationships of a resource in relationships member so that in case a resource has like 10-15 relations and you are requesting a collection of 100 resources then it will be a really heavy operation. Wich I think would be nice to avoid having this as a default behavior of this library.

If you still think that it is a good solution for you. You might try to overwrite this method ResourceTrait::getResourceRelationships so that it will ignore $linked parameter for those models that you consider as global dependencies.

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