Options
All
  • Public
  • Public/Protected
  • All
Menu

Defines a relationship from a LOCAL model.field to a REMOTE model.field and helps navigate the relationship, providing a simplified peek at the relationship details pertinent to setting FK's and constructing join conditions.

Because I mean, relationships are tough.

Type parameters

  • T

Hierarchy

  • ModelRelationship

Index

Constructors

constructor

Accessors

field

field:

The virtual/computed field on the local model that should contain the related model.

isComplete

isComplete:

Whether this relationship everything necessary to get, set, and query from the perspective of the local model provided at instantiation.

localConstructor

localConstructor:

The constructor that can be used to query DataStore or create instance for the local model.

localJoinFields

localJoinFields:

The field names on the local model that can be used to query or queried to match with instances of the remote model.

Fields are returned in-order to match the order of this.remoteKeyFields.

localPKFields

localPKFields:

The field names on the local model that uniquely identify it.

These fields may or may not be relevant to the join fields.

remoteDefinition

remoteDefinition:

remoteJoinFields

remoteJoinFields:

The field names on the remote model that can used to query or queried to match with instances of the local model.

Fields are returned in-order to match the order of this.localKeyFields.

remoteModelConstructor

remoteModelConstructor:

Constructor that can be used to query DataStore or create instances for the remote model.

remotePKFields

remotePKFields:

The field names on the remote model that uniquely identify it.

These fields may or may not be relevant to the join fields.

type

type:

The name/type of the relationship the local model has with the remote model via the defined local model field.

Methods

createLocalFKObject

  • createLocalFKObject(remote: any): object
  • Creates an FK mapper object with respect to the given related instance.

    E.g., if the local FK fields are [parentId, parentName] and point to [customId, name] on the remote model, createLocalFKObject(remote) will return:

    {
        parentId: remote.customId,
        parentName: remote.name
    }

    Parameters

    • remote: any

      The remote related instance.

    Returns object

createRemoteQueryObject

  • createRemoteQueryObject(local: T): object
  • Creates an query mapper object to help fetch the remote instance(s) or null if any of the necessary local fields are null or undefined.

    E.g., if the local FK fields are [parentId, parentName] and point to [customId, name] on the remote model, createLocalFKObject(remote) will return:

    {
        customId: local.parentId
        name: local.parentName
    }

    If the local fields are not populated, returns

    Parameters

    • local: T

      The local instance.

    Returns object

Static allFrom

Static from

  • Returns a ModelRelationship for the the given model and field if the pair indicates a relationship to another model. Else, returns null.

    Type parameters

    • T

    Parameters

    • model: ModelMeta<T>

      The model the relationship field exists in.

    • field: string

      The field that may relates the local model to the remote model.

    Returns ModelRelationship<T>