question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Accessing related object not in the store

See original GitHub issue

If 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:closed
  • Created 6 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
yury-dymovcommented, Jul 14, 2017

Thank you for your contribution and kind words 😃

0reactions
JakeDluhycommented, Jul 13, 2017

Thanks! Btw, I’m loving this library (and json-api-normalizer). It’s really cleaning up our implementation of JSON API!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found