2015-10-07 57 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变量。

相关问题