作为反应,我有以下脱机运行的代码。我显然找到了它。:
async function deleteMessage() {
toDelete = await DataStore.query(Message, c => c.id("eq","4faebf3b-f89a-4e34-978a-0fea611897e0"))
alert("toDelete: " + !toDelete ? toDelete : toDelete.length )
if (!toDelete || (toDelete !== undefined && toDelete.length == 0))
{
alert("Nothing to delete")
return
}
alert("Deleting " + toDelete.length + " records.")
alert("id for 0 = " + toDelete[0].id + " title: " + toDelete[0].title + " color: " + toDelete[0].color + " createdAt: " + toDelete[0].createdAt)
await DataStore.delete(toDelete);
alert("after delete")
// updateFormState(initialState)
}
toDelete 的所有字段都是正确的,并且在实际删除之前显示在警报中,因此 toDelete 应该是正确的模型。
一个警报说:删除 1 条记录。
下一个警报说: id for 0 = 4faebf3b-f89a-4e34-978a-0fea611897e0 标题:aaasdfasdf 颜色:#6c2f2f createdAt:未定义
但它永远不会从删除中返回,我收到错误消息:
Unhandled Rejection (Error): Object is not an instance of a valid model
DataStore.<anonymous>
C:/Projects/React/src/datastore/datastore.ts:897
894 | sortPredicate = ModelSortPredicateCreator.createFromExisting(modelDefinition, paginationProducer.sort);
895 | }
896 | return {
> 897 | limit: limit,
| ^ 898 | page: page,
899 | sort: sortPredicate,
900 | };
View compiled
我错过了什么?
此外,模型是:
type Message @model {
id: ID!
title: String!
color: String
createdAt: String
}
谢谢。