3

Lets say I have a Base entity that implements typeorm TableInheritance (single table inheritance), and I have two deriving entities: A and B.

I want to be able to change the entity type of A to B. something like this:

const a = em.findOne(A, {}) // found one entity - entityType column is now 'A'
em.save(a as B)
em.findOne(A, {}) // nothing is found
em.findOne(B, {}) // found one entity - entityType column is now 'B'

The uid is the same and typeorm won't let me simply insert \ update.

Anyone know a way to do this? My current solution is deleting and resaving but that might be problematic with cascading relations.

Ella
  • 71
  • 3

1 Answers1

2

Convert entity with uid from A to B:

await em.update(A, { uid: uid }, {[entityTypeColumnName]: 'B'})
Ella
  • 71
  • 3