Skip to content
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

Handling missing entry in related entity state #1854

Open
nbitouze opened this issue Mar 12, 2023 · 0 comments
Open

Handling missing entry in related entity state #1854

nbitouze opened this issue Mar 12, 2023 · 0 comments

Comments

@nbitouze
Copy link

Let's say I have a Book entity like

interface Book {
 authorId: string;
 author: Author;
 // ...
}

I can use relatedEntitySelector and combine it with rootEntity to get a selector that returns books where the authorId field has been automatically looked up in my Author state to hydrate the author field.

Now let's say that' I have too many authors to load them all upfront. The authorId will most likely not find an entity matching authorId. It would be great to have a way to detect these misses.

I think that what currently happens in the callback defined in relatedEntity is that simply ignore the issue:

        // Line ~120 in relatedEntity.ts
        const valueEntities = [];
        for (const id of ids) {
            if (!featureState.entities[id]) {
                continue; // Ignore related ids that don't appear in the matching feature state
            }

            // ...

            entityValue = {...featureState.entities[id]} as RELATED_ENTITY;

            // ...

            valueEntities.push(entityValue);
        }

Is there any suggestion or best practice to do that? If I haven't missed any build-in functionality, I guess my options are:

  • Put all of this logic further down the line once the selectors have returned my entities. Unfortunately at that point I need to define my relationships again, I can't just build upon what I've defined with relatedEntitySelector.
  • Re-define relatedEntity and before the above continue statement, do something interesting (most likely call a user-defined function).

Thank you.

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

1 participant