Skip to main content
Version: Next

ScalarReference <Value>

Wrapper for lazy scalar properties that provides on-demand loading from the database.

Index

Constructors

constructor

  • Parameters

    • optionalvalue: Value
    • initialized: boolean = ...

    Returns ScalarReference<Value>

Methods

bind

  • bind<Entity>(entity, property): void
  • Binds this scalar reference to a specific entity and property for lazy loading support.


    Parameters

    Returns void

isInitialized

  • isInitialized(): boolean
  • Returns whether the scalar value has been loaded.


    Returns boolean

load

  • load(options): Promise<undefined | Value>
  • Ensures the underlying entity is loaded first (without reloading it if it already is loaded). Returns either the whole entity, or the requested property.


    Parameters

    Returns Promise<undefined | Value>

loadOrFail

  • loadOrFail(options): Promise<Value>
  • 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).


    Parameters

    Returns Promise<Value>

set

  • set(value): void
  • Sets the scalar value and marks the reference as initialized.


    Parameters

    • value: Value

    Returns void

unwrap

  • unwrap(): undefined | Value
  • Returns the current scalar value, or undefined if not yet loaded.


    Returns undefined | Value

staticisScalarReference