KeystoneJS关系字段不保存空值

问题描述:

KeystoneJS定期Relationship场(categories在这个例子中):KeystoneJS关系字段不保存空值

Post.add({ 
    author: { type: Types.Relationship, ref: 'User' }, 
    categories: { type: Types.Relationship, ref: 'PostCategory', many: true } 
}); 

最初它是空的,但是当我增加一些价值给它,保存它,然后将其清除(所以该字段再次为空),保存此型号不会更新categories

Post.schema.pre('save', ...console.log(this.categories)表明this.categories有以前的值,而它应该是空的

有关此行为的任何想法?

显然这是KeystoneJS的“功能”。

Here他们忽略更新如果value === undefined,这是不幸的情况下,当你有一个值,并删除它。

解决方案:我感动的是undefined检查下来this line,所以它看起来是这样的:

else if ((value === undefined || !value) && item.get(this.path)) { ... }