Skip to content

Feature Proposal: Associated entities #40

@LFDM

Description

@LFDM

Let's consider having an entity called User and an entity called UserSettings. Each user has exactly one user settings object. A UserSettings object has a reference id to its user object in a field called userId.

The goal is to get more clever invalidations. Right now we can only say, that a change to a User should invalidate all UserSettings objects we have in our cache. By defining an association between these two entities, we could automatically do more fine grained invalidations. Only when the user with id x changes, the settings object with a reference id of x is invalidated.

The configuration for this could live in the regular config object, passed to build:

{
  user: {
    api: userApi
  },
  userSettings: {
    api: userSettingsApi,
    associatedEntity: 'user',
    associationIdFrom: (userSettings) => userSettings.userId
  }
}

Alternatively several such associations could be defined:

{
  user: {
    api: userApi
  },
  userSettings: {
    api: userSettingsApi,
    associatedEntities: [{ entity: 'user', referenceIdFrom: (userSettings) => userSettings.userId }]
  }
}

Does this sound like a legitimate and valuable use case?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions