Load relationships without going through includes
See original GitHub issuehttps://twitter.com/mwpastore/status/969315305863417856
when I do foo.load(‘bar’), why does it hit /api/foo/1?include=bar
instead of /api/foo/1/relationships/bar
? The latter would allow me to e.g. filter foo’s bar collection. Maybe storefront needs an additional interface?
Issue Analytics
- State:
- Created 6 years ago
- Comments:18 (8 by maintainers)
Top Results From Across the Web
laravel eloquent - Use without on nested eager loaded relations
The Eloquent\Model has a newQueryWithoutRelationships . I think you could do the following: (new A())->newQueryWithoutRelationships()->with( ...
Read more >Eloquent: Relationships - The PHP Framework For Web Artisans
Dynamic properties are "lazy loading", meaning they will only load their relationship data when you actually access them. Because of this, developers often...
Read more >Relationship Loading Techniques
The loading of relationships falls into three categories; lazy loading, eager loading, and no loading. Lazy loading refers to objects are ...
Read more >Mental Load: Examples, How to Talk About It, & More
The mental load can be a big burden when one person is left to carry it. ... Emotional labor also shows up in...
Read more >How to check if an relationship has been eager loaded or not
How can I check if a relationship has been loaded or not? I.e.: Copy Code $user->posts. I used to do: Copy Code if(!isset($user->posts))...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ve had a few conversations with folks and I think I have some API changes that will solve a number of these cases.
Goal
To provide an API for explicitly loading relationship data. This allows for code that is easier to reason about. Calls to
model.get('relationship')
will return whatever data is in the store, while calls tomodel.load('relationship')
will fetch data from the backend.Current problem
load('relationship')
uses a JSON:API include query to sideload a models relationship. While this works for most JSON:API backends, it does not work if the API layer wants the client to userelationship.links
to load data.Proposed solution
Add
model.sideload('relationship')
. This will work exactly howload
works today, it will fetch the model and slideload it’s relationship. It will return a cached result if the relationship has already been loaded. Since it is using JSON:API’s include parameter to fetch data it has the added benefit of fetching multiple relationships in one go (example:post.sideload('comments.author,favorites')
).Change
model.load('relationship')
to use relationship.links. This will allow the client to fetch data from URLs provided by the backend without using the include pattern.These new APIs will be backwards compatible, if you are using
load()
today it will continue to work.Options
Each of these methods will take an options hash as its last parameter. This will allow for force reloading the relationships data.
It will also allow developers to implement their own query param logic by overloading the
load
method on a model-by-model basis. Since sending query param data while loading relationships is not supported by ember-data the user will have to write this logic themselves.Other
Instead of naming the method
sideload
, we could call itinclude
.Ok, this feature has been released in
0.14.0
. 🎉Two changes to
load
…