2017-10-04 2 views
0

정기 Relationship 필드를 저장하지 :KeystoneJS 관계 필드 (이 예에서는 <code>categories</code>) 빈 값을 <a href="http://keystonejs.netlify.com/api/field/relationship/" rel="nofollow noreferrer">KeystoneJS</a>에

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)) { ... }