2015-10-07 75 views
0

我正在嘗試創建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

回答

1

這是由於命令流星加載文件。請參閱文件加載順序部分here

There are several load ordering rules. They are applied sequentially to all applicable files in the application, in the priority given below:

  1. HTML template files are always loaded before everything else
  2. Files beginning with main. are loaded last
  3. Files inside any lib/ directory are loaded next
  4. Files with deeper paths are loaded next
  5. Files are then loaded in alphabetical order of the entire path

例如,將app/lib/collections/sites.js重命名爲app/lib/collections/a_sites.js,並在加載content_types.js文件時定義Sites變量。

相關問題