Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js TypeORM迁移将id列绑定到对象_Node.js_Typeorm - Fatal编程技术网

Node.js TypeORM迁移将id列绑定到对象

Node.js TypeORM迁移将id列绑定到对象,node.js,typeorm,Node.js,Typeorm,我在postgres-issues和projects中创建了两个表。每个问题都来自一个项目,因此问题表中存在一个项目id外键。 在运行“typeorm model generator”而不是在类型号为的问题中获取projectId字段之后,我得到了类型为project的projectId。我是不是错过了一个场景 数据库:postgres 打字版本:0.1.12 @entity('Issue') export class Issue { @ManyToOne(type => Project

我在postgres-issues和projects中创建了两个表。每个问题都来自一个项目,因此问题表中存在一个项目id外键。 在运行“typeorm model generator”而不是在类型号为的问题中获取projectId字段之后,我得到了类型为project的projectId。我是不是错过了一个场景

数据库:postgres 打字版本:0.1.12

@entity('Issue')
export class Issue {

@ManyToOne(type => Project, projectId => projectId.issues)
@JoinColumn({ name: 'projectId'})
projectId: Project; // this should be of type number and a new field called project should be created with type "project". 

...

}

我在我的实体中以这种方式使用它:

@Entity()
export class Issue {

    @ManyToOne(type => Project, project => project.issues)
    project: Project

    @RelationId((issue: Issue) => issue.project)
    projectId: number;

    ...
}
它工作正常,但不确定它是否是最佳实践。 希望能有帮助