* 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>>)
| 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. |
nothing calls this directly
no test coverage detected