【发布时间】:2020-04-30 12:10:33
【问题描述】:
我有一个对象的以下配置:
export class Network {
@PrimaryColumn({ name: "id" })
id: string;
@Column("text")
url: string;
@ManyToOne(
type => User,
user => user.users,
{ nullable: true, onDelete: "SET NULL", onUpdate: "CASCADE" }
)
csm: User;
get_data(): {} {
return {
id: this.id,
url: this.url,
csm: this.csm ? this.csm.id : null,
};
}
}
User 是另一个类,它不涉及网络
当我保存数据时,它工作正常:
在我的表中,我有一列 csmId 用适当的用户 ID 来完成。
实现这些价值的程序看起来像
my_network.csm=csm 其中 csm 是一个用户对象。
现在,当我尝试使用函数get_data() 检索我的数据时,csm 始终为空,无论如何。其他值得到适当满足
有人可以帮忙吗?
非常感谢
【问题讨论】:
-
this在get_data()函数中是什么? -
@noamsteiner:
this是网络对象。我改变了我的描述,让你更好地理解。
标签: typescript typeorm many-to-one