Accessing related object not in the store
See original GitHub issueIf I have users
that have many books
, and I make a request for a user
object without sideloading the related books, then I might have the following structure in my store:
{
users: {
'1': {
id: '1',
type: 'users',
attributes: {},
relationships: {
books: {
data: {
[{
id: '1',
type: 'books'
}, {
id: '2',
type: 'books'
}]
}
}
}
}
},
books: {}
}
If I run const user = build(state.entities, 'users', '1')
then I get the user back. However if I then run user.books
I get [null, null]
. I would expect that I should get
[{
id: '1',
type: 'books'
}, {
id: '2',
type: 'books'
}]
I have experienced many use cases where I don’t need the full related object, just the id (to provide a link to that object, for instance) and so I won’t include
the related resources.
I’d be happy to make the changes if you would accept a PR!
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
Accessing Data in Related Objects Overview - Salesforce Help
You can achieve this by creating a data repeater (1) that's connected to Accounts, and adding a data element (2) to it that...
Read more >Storing and accessing related objects in postgres
I have a products table, and a separate table that I'd like to store related products in which consists ...
Read more >Related objects reference - Django documentation
Using add() on a relation that already exists won't duplicate the relation, but it will still trigger signals. For many-to-many relationships add() accepts ......
Read more >Working with Related Objects - SQLAlchemy 1.4 Documentation
In the section Loading Relationships we introduced the concept that when we work with instances of mapped objects, accessing the attributes that are...
Read more >Using Junction object to display related list
I had this issue as well. Looks like the solution is to ensure you have Master Detail Relationship fields on your junction object....
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
Thank you for your contribution and kind words 😃
Thanks! Btw, I’m loving this library (and
json-api-normalizer
). It’s really cleaning up our implementation of JSON API!