Reference <T>
Hierarchy
- Reference
Index
Constructors
constructor
Parameters
entity: T
Returns Reference<T>
Methods
getEntity
Returns T
getProperty
Parameters
prop: K
Returns T[K]
isInitialized
Returns boolean
load
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
Parameters
prop: K
optionaloptions: LoadReferenceOrFailOptions<TT, P, *, never>
Returns Promise<Loaded<TT, P>[K]>
populated
Parameters
optionalpopulated: boolean
Returns void
toJSON
Parameters
rest...args: any[]
Returns Dictionary
unwrap
Returns T
staticcreate
staticcreateFromPK
Parameters
entityType: EntityClass<T>
pk: T extends { [PrimaryKeyProp]?: PK } ? 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 { uuid?: PK } ? ReadonlyPrimary<PK> : T extends { id?: PK } ? ReadonlyPrimary<PK> : T
optionaloptions: { schema?: string }
optionalschema: string
Returns Ref<T>
staticcreateNakedFromPK
Parameters
entityType: EntityClass<T>
pk: T extends { [PrimaryKeyProp]?: PK } ? 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 { uuid?: PK } ? ReadonlyPrimary<PK> : T extends { id?: PK } ? ReadonlyPrimary<PK> : T
optionaloptions: { schema?: string }
optionalschema: string
Returns T
staticisReference
Checks whether the argument is instance of
Reference
wrapper.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
Reference
wrapper if the property is defined asref
.Parameters
entity: T | Reference<T>
prop: EntityProperty<O, T>
Returns T | Reference<T>
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.