Contest
컬렉션의 KeystoneJS (몽구스) 모델을 쓰려고합니다. 이 내 실제 모델의 단순화 된 버전입니다 :필터 KeystoneJS id 단위의 관계
대회
Contest.add({
title: {
type: Types.Text,
initial: true,
required: true,
index: true
},
state: {
type: Types.Select,
options: ['draft', 'started', 'finished', 'resolved'],
default: 'draft'
},
awards: {
idContest: { /* <--- copy of _id */
type: Types.Text,
hidden: true
},
jury: {
winner: {
type: Types.Relationship,
ref: 'Entry',
many: false,
filters: {
'contest.id': ':idContest', /* <--- filter */
'contest.state': 'admited'
}
}
}
}
});
항목 당신은 내가 항목 만 표시 할 winner
관계를 필터링하기 위해 노력하고있어 볼 수 있듯이
Entry.add({
title: {
type: Types.Text,
initial: true,
required: true,
index: true
},
author: {
type: Types.Relationship,
ref: 'User',
initial: true,
index: true
},
contest: {
id: {
type: Types.Relationship,
ref: 'Contest',
index: true
},
state: {
type: Types.Select,
options: ['none', 'review', 'admited', 'rejected'],
default: 'none',
}
}
});
이 콘테스트에 참가하는 그러나 나는 그것을 할 수 없었다 대회의 id
또는 _id
그래서 난 그냥으로 가득 새로운 더미 필드 awards.idContest
생성 :
Contest.schema.pre('save', function(next) {
this.awards.idContest = (this.id || this._id);
next();
});
가 어떻게 같은 있지만 추가 필드없이 달성 할 수 있습니까? 같은 뭔가 : 나는 내 댓글 이전에 언급 한 바와 같이
jury: {
winner: {
type: Types.Relationship,
ref: 'Entry',
many: false,
filters: {
'contest.id': ':id',
'contest.state': 'admited'
}
}
}
'배심원'필드에서 참조하는 '입력'목록의 정의를 제공 할 수 있습니까? 그것 없이는 결정적인 대답을하는 것이 어려울 것입니다. – JME
@JohnnyEstilles 'Entry' 모델을 추가했습니다. 고맙습니다. –
Ignacio, 매우 흥미로운 사용 사례입니다. Keystone의'filters' 옵션에는 현재 이러한 필터를 수행 할 수있는 기능이 없습니다. 나중에 오늘 내가 원하는 기능을 추가하고 문서화하기 위해 PR을 제출할 것입니다. 나는 PR이 합병 되 자마자 여기에 답변을 올릴 것입니다. – JME