【发布时间】:2020-12-16 04:46:17
【问题描述】:
我未能公开实体中的外键列,我觉得不能这样做很奇怪。
如果我不急于加载关系,至少我应该能够看到imageId 以了解关系存在的一些线索。所以当我做userRepository.findOne({email: emailaddress}) 时,即使我知道我不能以这种方式eager load 图像。但至少我可以看到imageId。
@Column('datetime', { nullable: true, name: 'last_login' })
lastLogin: string;
@OneToOne(() => UserSetting)
@JoinColumn({ name: 'setting_id' })
setting: UserSetting;
@OneToOne(() => UserImage, { onDelete: 'SET NULL' })
@JoinColumn({ name: 'image_id' })
image: UserImage;
imageUrl: { preview: string, thumbnail: string };
@OneToMany(() => Contact, contact => contact.user)
contacts: Contact[];
@OneToMany(() => Notification, notification => notification.user)
notifications: Notification[];
如您所见,没有定义imageId。我试着这样说。数据库无法同步,它也清除了我所有的图像数据。
@Column({name: 'image_id' })
imageId: string;
@OneToOne(() => UserImage, { onDelete: 'SET NULL' })
@JoinColumn({ name: 'image_id' })
image: UserImage;
我在这里遗漏了一些简单的东西吗?
【问题讨论】:
标签: typeorm