Skip to content

Handling missing entry in related entity state #1854

@nbitouze

Description

@nbitouze

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions