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

Method shouldRefresh

packages/core/src/EntityManager.ts:3049–3079  ·  view source on GitHub ↗

* when the entity is found in identity map, we check if it was partially loaded or we are trying to populate * some additional lazy properties, if so, we reload and merge the data from database

(meta: EntityMetadata<T>, entity: T, options: FindOneOptions<T, P, F, E>)

Source from the content-addressed store, hash-verified

3047 * some additional lazy properties, if so, we reload and merge the data from database
3048 */
3049 protected shouldRefresh<
3050 T extends object,
3051 P extends string = never,
3052 F extends string = never,
3053 E extends string = never,
3054 >(meta: EntityMetadata<T>, entity: T, options: FindOneOptions<T, P, F, E>): boolean {
3055 if (!helper(entity).__initialized || options.refresh) {
3056 return true;
3057 }
3058
3059 let autoRefresh: boolean;
3060
3061 if (options.fields) {
3062 autoRefresh = options.fields.some(field => !helper(entity).__loadedProperties.has(field as string));
3063 } else {
3064 autoRefresh = meta.comparableProps.some(prop => {
3065 const inlineEmbedded = prop.kind === ReferenceKind.EMBEDDED && !prop.object;
3066 return !inlineEmbedded && !prop.lazy && !helper(entity).__loadedProperties.has(prop.name);
3067 });
3068 }
3069
3070 if (autoRefresh || options.filters) {
3071 return true;
3072 }
3073
3074 if (Array.isArray(options.populate)) {
3075 return options.populate.some(field => !helper(entity).__loadedProperties.has(field as string));
3076 }
3077
3078 return !!options.populate;
3079 }
3080
3081 protected prepareOptions(
3082 options: (

Callers 1

findOneMethod · 0.80

Calls 2

helperFunction · 0.85
hasMethod · 0.65

Tested by

no test coverage detected