Gre*_*yea 6 typescript typeorm typegraphql
我已经查看了这些示例,据我所知,我严格按照它们进行操作...我的 @ManyToOne 连接按预期在查询中运行,但 @OneToMany 包含在我的 graphql 游乐场调用中时似乎没有触发。除设备信息外,用户的所有其他数据均按预期返回
这是在我的 User.ts 实体中:
@Field(type => [Devices], { nullable: true })
@OneToMany(() => Devices, devices => devices.user)
devices: Devices[];
Run Code Online (Sandbox Code Playgroud)
这是我的 Devices.ts 实体中的条目:
Field(type => User)
@ManyToOne(type => User, { lazy: true })
@JoinColumn([{ name: "userId", referencedColumnName: "userId" }])
user: User;
Run Code Online (Sandbox Code Playgroud)
在我添加上面的 nullable: true 之前,我只是收到一个错误,说不能为所需的内容返回 null 等等...我想也许我有一个没有用户的设备,但事实并非如此..在终端查询输出中它只查询用户表并且不尝试获取设备......
我的 graphql 调用非常简单,但只为所有设备返回 null:
{
users{
name
phone
devices{
deviceId
}
}
}
Run Code Online (Sandbox Code Playgroud)
我的 @ManyToOne 也为用户返回空值,直到我设置 {lazy: true },我也不知道为什么。。显然没有像 @OneToMany 这样的设置。我是一个续集,javascript 宝贝,这是我的第一次破解 TypeORM,所以任何帮助将不胜感激。或者,如果我还没有输入相关代码,请告诉我,我会做的。提前干杯
有趣......我几乎在任何地方都没有看到这样的例子,但我最终也添加了
{ lazy: true }调用@OneToMany,它们现在可以工作了。我没有意识到这是一个选择
@Field(type => [Devices], { nullable: true, })
@OneToMany(() => Devices, devices => devices.user, { lazy: true })
devices: Devices[];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1632 次 |
| 最近记录: |