Skip to main content
Version: 6.2

Reference <T>

Hierarchy

Index

Constructors

constructor

  • Type parameters

    • T: object

    Parameters

    • entity: T

    Returns Reference<T>

Methods

getEntity

  • getEntity(): T
  • Returns T

getProperty

  • getProperty<K>(prop: K): T[K]
  • Type parameters

    • K: string | number | symbol

    Parameters

    • prop: K

    Returns T[K]

isInitialized

  • isInitialized(): boolean
  • Returns boolean

load

  • Ensures the underlying entity is loaded first (without reloading it if it already is loaded). Returns the entity. If the entity is not found in the database (e.g. it was deleted in the meantime, or currently active filters disallow loading of it) the method returns null. Use loadOrFail() if you want an error to be thrown in such a case.


    Type parameters

    • TT: object
    • P: string = never
    • F: string = *
    • E: string = never

    Parameters

    Returns Promise<null | Loaded<TT, P, F, E>>

loadOrFail

  • Ensures the underlying entity is loaded first (without reloading it if it already is loaded). Returns the entity or throws an error just like em.findOneOrFail() (and respects the same config options).


    Type parameters

    • TT: object
    • P: string = never
    • F: string = *
    • E: string = never

    Parameters

    Returns Promise<Loaded<TT, P, F, E>>

loadProperty

  • Type parameters

    • TT: object
    • P: string = never
    • K: string | number | symbol = keyof TT

    Parameters

    Returns Promise<Loaded<TT, P>[K]>

populated

  • populated(populated?: boolean): void
  • Parameters

    • optionalpopulated: boolean

    Returns void

toJSON

unwrap

  • unwrap(): T
  • Returns T

staticcreate

staticcreateFromPK

  • createFromPK<T>(entityType: EntityClass<T>, pk: T extends { [PrimaryKeyProp]?: PK } ? PK extends keyof T ? ReadonlyPrimary<UnwrapPrimary<T[PK]>> : PK extends keyof T[] ? ReadonlyPrimary<PrimaryPropToType<T, PK>> : PK : T extends { _id?: PK } ? string | ReadonlyPrimary<PK> : T extends { uuid?: PK } ? ReadonlyPrimary<PK> : T extends { id?: PK } ? ReadonlyPrimary<PK> : T, options?: { schema?: string }): T extends Scalar ? ScalarReference<T> : EntityRef<T>
  • Type parameters

    • T: object

    Parameters

    • entityType: EntityClass<T>
    • pk: T extends { [PrimaryKeyProp]?: PK } ? PK extends keyof T ? ReadonlyPrimary<UnwrapPrimary<T[PK]>> : PK extends keyof T[] ? ReadonlyPrimary<PrimaryPropToType<T, PK>> : PK : T extends { _id?: PK } ? string | ReadonlyPrimary<PK> : T extends { uuid?: PK } ? ReadonlyPrimary<PK> : T extends { id?: PK } ? ReadonlyPrimary<PK> : T
    • optionaloptions: { schema?: string }

    Returns T extends Scalar ? ScalarReference<T> : EntityRef<T>

staticcreateNakedFromPK

  • createNakedFromPK<T>(entityType: EntityClass<T>, pk: T extends { [PrimaryKeyProp]?: PK } ? PK extends keyof T ? ReadonlyPrimary<UnwrapPrimary<T[PK]>> : PK extends keyof T[] ? ReadonlyPrimary<PrimaryPropToType<T, PK>> : PK : T extends { _id?: PK } ? string | ReadonlyPrimary<PK> : T extends { uuid?: PK } ? ReadonlyPrimary<PK> : T extends { id?: PK } ? ReadonlyPrimary<PK> : T, options?: { schema?: string }): T
  • Type parameters

    • T: object

    Parameters

    • entityType: EntityClass<T>
    • pk: T extends { [PrimaryKeyProp]?: PK } ? PK extends keyof T ? ReadonlyPrimary<UnwrapPrimary<T[PK]>> : PK extends keyof T[] ? ReadonlyPrimary<PrimaryPropToType<T, PK>> : PK : T extends { _id?: PK } ? string | ReadonlyPrimary<PK> : T extends { uuid?: PK } ? ReadonlyPrimary<PK> : T extends { id?: PK } ? ReadonlyPrimary<PK> : T
    • optionaloptions: { schema?: string }

    Returns T

staticisReference

  • isReference<T>(data: any): data is Reference<T>
  • Checks whether the argument is instance of Reference wrapper.


    Type parameters

    • T: object

    Parameters

    • data: any

    Returns data is Reference<T>

staticunwrapReference

staticwrapReference

  • Wraps the entity in a Reference wrapper if the property is defined as ref.


    Type parameters

    • T: object
    • O: object

    Parameters

    Returns T | Reference<T>