在我拥有Equipt
实体的下面,它具有三列createdById
,tribeId
,userId
。
我正在尝试使用每个实体的ID(而不是实体本身)保存新行:
这不起作用:
let e = connection.getRepository(Equipt);
const check = await e.save({
userId: 1,
tribeId: 1,
createdById: 1,
})
这有效:
let e = connection.getRepository(Equipt);
const check = await e.save({
user: user,
tribe: tribe,
createdBy: adminUser,
})
实体:
import {ManyToOne, RelationId, JoinColumn, Entity} from "typeorm";
import {User} from './User';
import { Base } from "../base";
import { Tribe } from "./Tribe";
@Entity('Equipts')
export class Equipt extends Base {
@ManyToOne(type => User, { nullable: false })
@JoinColumn()
createdBy: User;
@RelationId((Equipt: Equipt) => Equipt.createdBy)
createdById: number;
@ManyToOne(type => Tribe, { nullable: false })
@JoinColumn()
Tribe: Tribe;
@RelationId((Equipt: Equipt) => Equipt.Tribe)
TribeId: number;
@ManyToOne(type => User, { nullable: false })
@JoinColumn()
user: User;
@RelationId((Equipt: Equipt) => Equipt.user)
userId: number;
}
是否可以使用id插入而不让整个实体通过?