KeystoneJS 尝试将 createItem() 与 relationShip 字段一起使用

KeystoneJS trying to use createItem() with relationShip field

我是 KeystoneJS 的新手,我遇到了一个问题: 导入 CSV 后,我正在尝试在关系字段上使用 createItem()。由于 csvtojson 库,我将 CSV 的数据转换为 JSON 对象,然后基于我的 JSONObject.

创建了一个项目

这是我的关系声明:

project: { type: Types.Relationship, ref: 'Project' },

这是我的项目声明:

name: { type: Types.Text, required: true, index: true, refPath: 'project' }

但是当我使用 createItem() 方法时,这里出现一条错误消息:

留言:'Relationship Info.project contains an invalid reference: "Test".'}

我希望我已经足够清楚让你们帮助我,

此致。

我终于找到了解决办法,所以我把它给你。 不幸的是,我无法使用 Keystone Framework 中现有的 updateHandler 来完成它。相反,这是我所做的:

我使用查询从名称中找到对象的 ID:

var yourTableQuery = query.select('id').exec(function(err, yourTableId)

然后我用猫鼬的方式创建了一个对象:

item = new yourTable.model({ relationship: yourTableId })

link 完成。

希望这对你们中的一些人有所帮助!