Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
687 views
in Technique[技术] by (71.8m points)

node.js - TypeORM single table inheritance use abstract classes between @Entity() and @ChildEntity()

I would like to achieve the following single table inheritance with TypeORM:

@Entity()
@TableInheritance({column: {type: "varchar", name: "type"}})
export class BaseDevice {

  @PrimaryGeneratedColumn({type: "uuid"})
  id: string;

  // other fields
}

abstract class MeasureableDevice extends BaseDevice {

  @Column()
  value: string;

  // other fields
}

@ChildEntity()
export class TemperatureSensor extends MeasureableDevice {

  @Column()
  position: string;

  // other fields
}

But when I run my application, I get the following error:

(node:2574710) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'build' of undefined at /node_modules/typeorm/metadata-builder/EntityMetadataBuilder.js:526:83 at Array.forEach () at EntityMetadataBuilder.computeEntityMetadataStep2 (/node_modules/typeorm/metadata-builder/EntityMetadataBuilder.js:526:37) at /node_modules/typeorm/metadata-builder/EntityMetadataBuilder.js:81:74 at Array.forEach () at EntityMetadataBuilder.build (/node_modules/typeorm/metadata-builder/EntityMetadataBuilder.js:81:25) at ConnectionMetadataBuilder.buildEntityMetadatas (/node_modules/typeorm/connection/ConnectionMetadataBuilder.js:57:141) at Connection.buildMetadatas (/node_modules/typeorm/connection/Connection.js:514:57) at Connection. (/node_modules/typeorm/connection/Connection.js:127:30) at step (/node_modules/tslib/tslib.js:141:27) (Use node --trace-warnings ... to show where the warning was created) (node:2574710) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1) (node:2574710) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

When I remove the abstract class in between of @Entity() and @ChildEntity() classes and copy the @Column() fields of abstract class MeasureableDevice directly into class TemperatureSensor everything works. So it seems there is a problem with an abstract class in between those the annotated classes. Does anyone know how to solve this?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...