我是 NestJS 的新手(我在 Angular 方面有一些經驗)。undefined當我 console.log 一個 JoinTable 時我得到了(這些表是新的。我的任務是創建一個新的微服務)
所以Unit和Hub有One to One關系。
這里是單位
@Entity({
name: 'units',
})
export class UnitEntity {
@PrimaryGeneratedColumn()
id: number;
@OneToOne(() => HubEntity)
@JoinColumn({name: "hub_id"})
hub: HubEntity;
僅供參考,我也試過這樣編碼:
@OneToOne(type => HubEntity, hub => hub.unit)
@JoinColumn({name: "hub_id"})
hub: HubEntity;
對于集線器:
@Entity({
name: 'hubs',
})
export class HubEntity {
@PrimaryGeneratedColumn()
id: number;
@OneToOne(type => UnitEntity, unit => unit.hub)
@JoinColumn({name: "hub_id"})
unit: UnitEntity;
為了測驗,這就是我安慰它的方式。
async findAllByUnit(unitId: number) {
const unit = await this.unitRepository.findOne(unitId)
console.log(unit.hub)
}
它回傳undefined
請讓我知道我錯過了什么。
先謝謝啦~
uj5u.com熱心網友回復:
你必須包括這樣的關系:
await this.unitRepository.findOne(unitId, {
relations: ['hub']
})
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/430786.html
標籤:javascript 节点.js 巢穴 打字机
