我正在嘗試創建2個集合之間的關係,但其中一個集合不可用於其他引用。具體來說,我有2個集合:Sites和ContentTypes。這是他們包括:由於缺少集合對象導致Collection2關係錯誤
// app/lib/collections/sites.js
Sites = new Mongo.Collection('sites');
Sites.attachSchema(new SimpleSchema({
name: {
type: String,
label: "Name",
max: 100
},
client: {
type: String,
label: "Client",
max: 100
},
created: {
type: Date,
autoValue: function() {
if (this.isInsert) {
return new Date;
} else if (this.isUpsert) {
return {$setOnInsert: new Date};
} else {
this.unset(); // Prevent user from supplying their own value
}
}
}
}));
而這裏的CONTENTTYPES集合:
// app/lib/collections/content_types.js
ContentTypes = new Mongo.Collection('content_types');
ContentTypes.attachSchema(new SimpleSchema({
name: {
type: String,
label: "Name",
max: 100
},
machineName: {
type: String,
label: "Machine Name",
max: 100
},
site:{
type: Sites
},
created: {
type: Date,
autoValue: function() {
if (this.isInsert) {
return new Date;
} else if (this.isUpsert) {
return {$setOnInsert: new Date};
} else {
this.unset(); // Prevent user from supplying their own value
}
}
}
}));
當我添加的網站參考CONTENTTYPES模式,我的應用程序崩潰與錯誤:
ReferenceError: Sites is not defined at lib/collections/content_types.js:32:11
我還沒有找到很多運氣,找到收藏2中超過this的關係的文檔。它看起來像那裏引用的格式應該基於this thread。