MCPcopy Create free account
hub / github.com/mikro-orm/mikro-orm / load

Method load

packages/core/src/entity/Collection.ts:103–116  ·  view source on GitHub ↗

* Ensures the collection is loaded first (without reloading it if it already is loaded). * Returns the Collection instance (itself), works the same as `Reference.load()`.

(
    options: InitCollectionOptions<TT, P> = {},
  )

Source from the content-addressed store, hash-verified

101 * Returns the Collection instance (itself), works the same as `Reference.load()`.
102 */
103 async load<TT extends T, P extends string = never>(
104 options: InitCollectionOptions<TT, P> = {},
105 ): Promise<LoadedCollection<Loaded<TT, P>>> {
106 if (this.isInitialized(true) && !options.refresh) {
107 const em = this.getEntityManager(this.#items, false);
108 options = { ...options, filters: QueryHelper.mergePropertyFilters(this.property.filters, options.filters)! };
109 await em?.populate(this.#items, options.populate as any, options as any);
110 this.setSerializationContext(options);
111 } else {
112 await this.init({ refresh: false, ...options });
113 }
114
115 return this as unknown as LoadedCollection<Loaded<TT, P>>;
116 }
117
118 private setSerializationContext<TT extends T>(options: LoadHint<TT, any, any, any>): void {
119 helper(this.owner).setSerializationContext({

Callers 1

loadItemsMethod · 0.95

Calls 6

isInitializedMethod · 0.95
getEntityManagerMethod · 0.95
initMethod · 0.95
mergePropertyFiltersMethod · 0.80
populateMethod · 0.65

Tested by

no test coverage detected