(meta: EntityMetadata<Entity>, entity: Entity)
| 208 | |
| 209 | /** @internal */ |
| 210 | export function resetUntouchedCollections<Entity extends object>(meta: EntityMetadata<Entity>, entity: Entity): void { |
| 211 | // for entities passed in via `em.create()` and then upserted, collection-kind relations |
| 212 | // were initialized as empty-but-initialized by the hydrator (newEntity=true). once the |
| 213 | // upsert resolves the entity to a possibly existing row, that state is stale and would |
| 214 | // cause `em.populate()` to skip those collections. replace them with a fresh |
| 215 | // uninitialized collection so populate can load them. |
| 216 | if (helper(entity).__originalEntityData) { |
| 217 | return; |
| 218 | } |
| 219 | |
| 220 | for (const prop of meta.relations) { |
| 221 | if (prop.kind !== ReferenceKind.MANY_TO_MANY && prop.kind !== ReferenceKind.ONE_TO_MANY) { |
| 222 | continue; |
| 223 | } |
| 224 | |
| 225 | const collection = entity[prop.name]; |
| 226 | |
| 227 | if (Utils.isCollection(collection) && collection.isInitialized() && !collection.isDirty()) { |
| 228 | Collection.create(entity, prop.name, undefined, false); |
| 229 | } |
| 230 | } |
| 231 | } |
no test coverage detected