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

Method remove

packages/core/src/EntityManager.ts:2396–2419  ·  view source on GitHub ↗

* Marks entity for removal. * A removed entity will be removed from the database at or before transaction commit or as a result of the flush operation. * * To remove entities by condition, use `em.nativeDelete()`.

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

Source from the content-addressed store, hash-verified

2394 * To remove entities by condition, use `em.nativeDelete()`.
2395 */
2396 remove<Entity extends object>(entity: Entity | Reference<Entity> | Iterable<Entity | Reference<Entity>>): this {
2397 const em = this.getContext();
2398
2399 if (Utils.isEntity<Entity>(entity)) {
2400 // do not cascade just yet, cascading of entities in persist stack is done when flushing
2401 em.#unitOfWork.remove(entity, undefined, { cascade: false });
2402 return em;
2403 }
2404
2405 const entities = Utils.asArray(entity, true);
2406
2407 for (const ent of entities) {
2408 if (!Utils.isEntity(ent, true)) {
2409 throw new Error(
2410 `You need to pass entity instance or reference to 'em.remove()'. To remove entities by condition, use 'em.nativeDelete()'.`,
2411 );
2412 }
2413
2414 // do not cascade just yet, cascading of entities in remove stack is done when flushing
2415 em.#unitOfWork.remove(Reference.unwrapReference(ent), undefined, { cascade: false });
2416 }
2417
2418 return em;
2419 }
2420
2421 /**
2422 * Flushes all changes to objects that have been queued up to now to the database.

Callers

nothing calls this directly

Calls 5

getContextMethod · 0.95
asArrayMethod · 0.80
unwrapReferenceMethod · 0.80
removeMethod · 0.65
isEntityMethod · 0.45

Tested by

no test coverage detected