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

Method persist

packages/core/src/EntityManager.ts:2365–2388  ·  view source on GitHub ↗

* Tells the EntityManager to make an instance managed and persistent. * The entity will be entered into the database at or before transaction commit or as a result of the flush operation.

(entity: Entity | Reference<Entity> | Iterable<Entity | Reference<Entity>>)

Source from the content-addressed store, hash-verified

2363 * The entity will be entered into the database at or before transaction commit or as a result of the flush operation.
2364 */
2365 persist<Entity extends object>(entity: Entity | Reference<Entity> | Iterable<Entity | Reference<Entity>>): this {
2366 const em = this.getContext();
2367
2368 if (Utils.isEntity(entity)) {
2369 // do not cascade just yet, cascading of entities in persist stack is done when flushing
2370 em.#unitOfWork.persist(entity, undefined, { cascade: false });
2371 return em;
2372 }
2373
2374 const entities = Utils.asArray(entity);
2375
2376 for (const ent of entities) {
2377 if (!Utils.isEntity(ent, true)) {
2378 /* v8 ignore next */
2379 const meta = typeof ent === 'object' ? em.metadata.find((ent as Dictionary).constructor) : undefined;
2380 throw ValidationError.notDiscoveredEntity(ent, meta);
2381 }
2382
2383 // do not cascade just yet, cascading of entities in persist stack is done when flushing
2384 em.#unitOfWork.persist(Reference.unwrapReference(ent), undefined, { cascade: false });
2385 }
2386
2387 return this;
2388 }
2389
2390 /**
2391 * Marks entity for removal.

Callers

nothing calls this directly

Calls 7

getContextMethod · 0.95
asArrayMethod · 0.80
notDiscoveredEntityMethod · 0.80
unwrapReferenceMethod · 0.80
persistMethod · 0.65
findMethod · 0.65
isEntityMethod · 0.45

Tested by

no test coverage detected