2017-10-04 43 views
0

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有以前的值,而它應該是空的

有關此行爲的任何想法?

回答

0

顯然這是KeystoneJS的「功能」。

Here他們忽略更新如果value === undefined,這是不幸的情況下,當你有一個值,並刪除它。

解決方案:我感動的是undefined檢查下來this line,所以它看起來是這樣的:

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