简体   繁体   English

更新 TypeORM 单表继承中的实体类型

[英]Update entity type in TypeORM single table inheritance

Lets say I have a Base entity that implements typeorm TableInheritance (single table inheritance), and I have two deriving entities: A and B .假设我有一个实现typeorm TableInheritance (单表继承)的Base实体,并且我有两个派生实体: AB

I want to be able to change the entity type of A to B .我希望能够将A的实体类型更改为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. uid 是相同的,typeorm 不会让我简单地插入 \ 更新。

Anyone know a way to do this?有人知道这样做的方法吗? My current solution is deleting and resaving but that might be problematic with cascading relations.我目前的解决方案是删除和重新保存,但这可能与级联关系有问题。

将具有uid的实体从A转换为B

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM