Reference <T>
Hierarchy
- Reference
Index
Constructors
constructor
Type parameters
- T: object
Parameters
entity: T
Returns Reference<T>
Methods
getEntity
Returns T
getProperty
Type parameters
- K: string | number | symbol
Parameters
prop: K
Returns T[K]
isInitialized
Returns boolean
load
Type parameters
- TT: object
- P: string = never
- F: string = *
- E: string = never
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).Type parameters
- TT: object
- P: string = never
- F: string = *
- E: string = never
Parameters
options: LoadReferenceOrFailOptions<TT, P, F, E> = {}
Returns Promise<Loaded<TT, P, F, E>>
loadProperty
Type parameters
- TT: object
- P: string = never
- K: string | number | symbol = keyof TT
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
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 }
optionalschema: string
Returns Ref<T>
staticcreateNakedFromPK
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 }
optionalschema: string
Returns T
staticisReference
Checks whether the argument is instance of
Reference
wrapper.Type parameters
- T: object
Parameters
data: any
Returns data is Reference<T>
staticunwrapReference
Returns wrapped entity.
Type parameters
- T: object
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
.Type parameters
- T: object
- O: object
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.