* 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`. Use `loadOrFai
(
options: LoadReferenceOptions<TT, P, F, E> = {},
)
| 137 | * the method returns `null`. Use `loadOrFail()` if you want an error to be thrown in such a case. |
| 138 | */ |
| 139 | async load<TT extends T, P extends string = never, F extends string = never, E extends string = never>( |
| 140 | options: LoadReferenceOptions<TT, P, F, E> = {}, |
| 141 | ): Promise<Loaded<TT, P, F, E> | null> { |
| 142 | const wrapped = helper(this.entity as TT & object); |
| 143 | |
| 144 | if (!wrapped.__em) { |
| 145 | return this.entity as Loaded<TT, P, F, E>; |
| 146 | } |
| 147 | |
| 148 | options = { ...options, filters: QueryHelper.mergePropertyFilters(this.property?.filters, options.filters)! }; |
| 149 | |
| 150 | if (this.isInitialized() && !options.refresh && options.populate) { |
| 151 | await wrapped.__em.populate(this.entity, options.populate as any, options as any); |
| 152 | } |
| 153 | |
| 154 | if (!this.isInitialized() || options.refresh) { |
| 155 | if ( |
| 156 | options.dataloader ?? |
| 157 | [DataloaderType.ALL, DataloaderType.REFERENCE].includes(wrapped.__em.config.getDataloaderType()) |
| 158 | ) { |
| 159 | const dataLoader = await wrapped.__em.getDataLoader('ref'); |
| 160 | return dataLoader.load([this, options]); |
| 161 | } |
| 162 | |
| 163 | return wrapped.init(options); |
| 164 | } |
| 165 | |
| 166 | return this.entity as Loaded<TT, P, F, E>; |
| 167 | } |
| 168 | |
| 169 | /** |
| 170 | * Ensures the underlying entity is loaded first (without reloading it if it already is loaded). |
no test coverage detected