Defines relations from one Resource to another (included in the document or external) and can resolve them.

This class is normally not used directly. It is used internally in the relatedResource, relatedResources and relatedDocuments accessors and you should use those if you just want to gain access to other resources.

If you need to work with relationships directly (e.g. to obtain meta data about the relationship itself), you can use the relationships accessor.

Remarks

Methods and accessors marked as memoized are only executed once per instance (the first time they are called) and return a cached result on subsequent calls.

See

https://jsonapi.org/format/1.0/#document-resource-object-relationships

Hierarchy

  • Relationship

Constructors

Properties

context: Context

The context to use to fetch related documents

The JSON:API relationship object from which to construct the relationship

referringDocument: Document

The document that contains the relationship

Accessors

  • get empty(): boolean
  • true if the relationship only contains a meta member and no data or links

    Memoized

    Returns boolean

  • Map of link names to Links defined under the links member of this relationship

    Memoized

    Returns undefined | Links

Methods

  • The Document referred to by the related link in the links member of the relationship. Fetches the related document from the server using the context given at construction and respecting any sparseFields of the referring document.

    Memoized

    Returns Promise<undefined | Document>

  • The one Resource referenced by this relationship. Resource linkage (the resource identifier found in the data member of this relationship) has priority. If there is no resource linkage, the primary resource found in relatedDocument is used.

    Throws

    CardinalityError if there are many resources.

    Throws

    SchemaError if neither a links nor a data member is present

    Memoized

    Returns Promise<undefined | null | Resource>

  • Works like the resource method, but prefers the related link instead of resource linkage. If no related link is present or if the link does not work, it falls back to the resource method.

    Throws

    CardinalityError if there are many resources.

    Throws

    SchemaError if neither a links nor a data member is present

    Memoized

    Returns Promise<undefined | null | Resource>

  • List of Resources referenced by this relationship (if there are many resources). Resource linkage (resource identifiers found in the data member of this relationship) has priority. If there is no resource linkage, the primary resources found in relatedDocument are used.

    Throws

    CardinalityError if there is only a singular resource.

    Throws

    SchemaError if neither a links nor a data member is present

    Memoized

    Returns Promise<Resource[]>

  • Works like the resources method, but prefers the related link instead of resource linkage. If no related link is present or if the link does not work, it falls back to the resources method.

    Throws

    CardinalityError if there is only a singular resource.

    Throws

    SchemaError if neither a links nor a data member is present

    Memoized

    Returns Promise<Resource[]>

Generated using TypeDoc