Reference <T>
Hierarchy
- Reference
Index
Constructors
constructor
Parameters
entity: T
Returns Reference<T>
Methods
getEntity
Returns the underlying entity, throwing an error if the reference is not initialized.
Returns T
getProperty
Returns the value of a property on the underlying entity. Throws if the reference is not initialized.
Parameters
prop: K
Returns T[K]
isInitialized
Returns whether the underlying entity has been fully loaded from the database.
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. UseloadOrFail()if you want an error to be thrown in such a case.Parameters
options: LoadReferenceOptions<TT, P, F, E> = {}
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).Parameters
options: LoadReferenceOrFailOptions<TT, P, F, E> = {}
Returns Promise<Loaded<TT, P, F, E>>
loadProperty
Loads the entity if needed, then returns the value of the specified property.
Parameters
prop: K
optionaloptions: LoadReferenceOrFailOptions<TT, P, *, never>
Returns Promise<Loaded<TT, P>[K]>
populated
Marks the underlying entity as populated or not for serialization purposes.
Parameters
optionalpopulated: boolean
Returns void
toJSON
Serializes the underlying entity to a plain JSON object.
Parameters
rest...args: any[]
Returns Dictionary
unwrap
Returns the underlying entity without checking initialization state.
Returns T
staticcreate
staticcreateFromPK
Creates a Reference wrapper for an entity identified by its primary key, wrapped in a Ref.
Parameters
entityType: EntityClass<T>
pk: T extends { [PrimaryKeyProp]?: PK } ? PK extends undefined ? Omit<T<T>, typeof PrimaryKeyProp> : PK extends keyof T<T> ? ReadonlyPrimary<UnwrapPrimary<T<T>[PK<PK>]>> : PK extends keyof T<T>[] ? ReadonlyPrimary<PrimaryPropToType<T<T>, PK<PK>>> : PK : T extends { _id?: PK } ? string | ReadonlyPrimary<PK> : T extends { id?: PK } ? ReadonlyPrimary<PK> : T extends { uuid?: PK } ? ReadonlyPrimary<PK> : T
optionaloptions: { schema?: string }
optionalschema: string
Returns Ref<T>
staticcreateNakedFromPK
Creates an uninitialized entity reference by primary key without wrapping it in a Reference.
Parameters
entityType: EntityClass<T>
pk: T extends { [PrimaryKeyProp]?: PK } ? PK extends undefined ? Omit<T<T>, typeof PrimaryKeyProp> : PK extends keyof T<T> ? ReadonlyPrimary<UnwrapPrimary<T<T>[PK<PK>]>> : PK extends keyof T<T>[] ? ReadonlyPrimary<PrimaryPropToType<T<T>, PK<PK>>> : PK : T extends { _id?: PK } ? string | ReadonlyPrimary<PK> : T extends { id?: PK } ? ReadonlyPrimary<PK> : T extends { uuid?: PK } ? ReadonlyPrimary<PK> : T
optionaloptions: { schema?: string }
optionalschema: string
Returns T
staticisReference
Checks whether the argument is instance of
Referencewrapper.Parameters
data: any
Returns data is Reference<T>
staticunwrapReference
Returns wrapped entity.
Parameters
ref: T | Reference<T> | ScalarReference<T> | Ref<T>
Returns T
staticwrapReference
Wraps the entity in a
Referencewrapper if the property is defined asref.Parameters
entity: T | Reference<T>
prop: EntityProperty<O, T>
Returns T | Reference<T>
Wrapper around an entity that provides lazy loading capabilities and identity-preserving reference semantics.