【发布时间】:2022-02-07 16:58:02
【问题描述】:
我只是得到这个错误。
Property 'forEach' does not exist on type 'ObjectId | [BaseAction]'.
错误在最后一行,代码是:
ServiceModel.findOne({name: "slack"}).populate({
path: 'actions',
model: 'BaseActionModel',
}).then((res) => {
if (!res?.actions) return // null verif
res.actions.forEach((action: BaseAction) => {
我搜索但我什么也没找到。 为了添加更多上下文,我的模型是:
@ObjectType({description: 'Services'})
export class Service {
@Field(() => ID)
id!: string;
@Field()
@Property()
name!: String;
@Field()
@Property()
out_url!: String;
@Field()
@Property()
in_url!: String;
@Field((_type) => [BaseAction])
@Property({ref: BaseAction})
actions: Ref<[BaseAction]>;
}
如果需要,您可以要求更多代码
【问题讨论】:
-
你能分享你的模型的架构吗?看起来动作是单个引用,而不是引用数组
标签: typescript mongoose typegraphql