我有一个关于collection2 与关系和自动生成的问题。我尝试实现 1:n 关系,其中每个对象恰好有 1 个 objectType,而每个 objectType 可以引用多个对象。
我的架构如下所示:
// register collections
Objects = new Mongo.Collection('objects');
ObjectTypes = new Mongo.Collection('objectTypes');
// define schema
var Schemas = {};
Schemas.ObjectType = new SimpleSchema({ // object type schema
name: {
type: String
}
});
Schemas.Object = new SimpleSchema({ // object schema
type: {
type: ObjectTypes.Schema,
optional: true
},
title: {
type: String
}
});
// attach schemas
ObjectTypes.attachSchema(Schemas.ObjectType);
Objects.attachSchema(Schemas.Object);
我的自动表单如下所示:
{{> quickForm collection="Objects" id="insertTestForm" type="insert"}}
我实际上希望我的 type 属性有一个选择选项字段,但是会出现一个文本输入。有谁知道为什么?
根据文档[1],它应该是一个选择选项字段:
If you use a field that has a type that is a Mongo.Collection instance, autoform will automatically provide select options based on _id and name fields from the related Mongo.Collection. You may override with your own options to use a field other than name or to show a limited subset of all documents. You can also use allowedValues to limit which _ids should be shown in the options list.
[1] https://github.com/aldeed/meteor-collection2/blob/master/RELATIONSHIPS.md#user-content-autoform
编辑 如果我使用
type: ObjectTypes,
代替
type: ObjectTypes.Schema,
我的应用程序崩溃,引发以下错误:
Your app is crashing. Here's the latest log.
/Users/XXX/.meteor/packages/meteor-tool/.1.1.3.ik16id++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/fibers/future.js:245
throw(ex);
^
RangeError: Maximum call stack size exceeded
Exited with code: 8
Your application is crashing. Waiting for file change.