* 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).
(
options: LoadReferenceOrFailOptions<TT, P, F, E> = {},
)
| 171 | * Returns the entity or throws an error just like `em.findOneOrFail()` (and respects the same config options). |
| 172 | */ |
| 173 | async loadOrFail<TT extends T, P extends string = never, F extends string = never, E extends string = never>( |
| 174 | options: LoadReferenceOrFailOptions<TT, P, F, E> = {}, |
| 175 | ): Promise<Loaded<TT, P, F, E>> { |
| 176 | const ret = await this.load(options); |
| 177 | |
| 178 | if (!ret) { |
| 179 | const wrapped = helper(this.entity); |
| 180 | options.failHandler ??= wrapped.__em!.config.get('findOneOrFailHandler'); |
| 181 | const entityName = this.entity.constructor.name; |
| 182 | const where = wrapped.getPrimaryKey() as any; |
| 183 | throw options.failHandler(entityName, where); |
| 184 | } |
| 185 | |
| 186 | return ret; |
| 187 | } |
| 188 | |
| 189 | private set<TT extends T>(entity: TT | Ref<TT>): void { |
| 190 | this.entity = Reference.unwrapReference(entity as T & object); |
no test coverage detected