【发布时间】:2020-07-14 17:21:54
【问题描述】:
我在我的 NestJS 项目中定义实体字段。我有成功定义的 ManyToOne 属性。我很难找到正确的方法来定义 OneToMany 关系以适应我用于其他关系的语法。
import {Entity,Column, PrimaryColumn, ManyToOne,JoinColumn,OneToMany} from "typeorm";
import { Account } from "./account.entity";
import { Balance } from "./balance.entity";
import { BaseEntity } from "./base.entity";
@Entity()
export class MainEntity extends BaseEntity {
@PrimaryColumn({
type: "varchar",
name: "id",
unique: true
})
id: string;
@ManyToOne(() => Account, { nullable: true })
@JoinColumn({
name: "account_id",
referencedColumnName: "id"
})
account: Account;
@OneToMay 关系需要连接到 Balance 实体并在其中 mappedBy paymentDevice 字段。
我的尝试:
@OneToMany(() => Balance, ...)
balances: Balance[]
我在 NestJs 和 typescript 中,所以这对我来说很有挑战性。
【问题讨论】:
标签: node.js typescript one-to-many nestjs typeorm