meteor - 带有嵌套 autoValue 的 SimpleSchema 无效键

标签 meteor schema

我有一个这样的模式(剪掉绒毛):

Schemas.people = new SimpleSchema({
  note: {
    type: [Schemas.notes],
    optional: true,
    defaultValue: []
  },
  updates: {
    type: [Schemas.updates],
    optional:true,
    autoValue:function(){
      if (this.isInsert) {
        return [{
          at: new Date,
          user_id: this.userId
        }];
      } 
      return {
        $push:{
          at: new Date,
          user_id: this.userId
        }
      }
    }
  }
});

注释模式如下所示:
Schemas.notes = new SimpleSchema({
  note: {
    type: String,
    autoform: {
      afFieldInput:{
        type:"textarea"
      }
    },
    optional: true
  },
  updates: {
    type: [Schemas.updates],
    optional:true,
    autoform:{
      omit:true
    },
    autoValue:function(){
      if (this.isInsert) {
        return [{
          at: new Date,
          user_id: this.userId
        }];
      } 
      return {
        $push:{
          at: new Date,
          user_id: this.userId
        }
      }
    }
  }
});

更新模式非常简单:
Schemas.updates = new SimpleSchema({
  at: {
    type: Date
  },
  user_id:{
    type: Meteor.ObjectID
  }
});
people 上的“更新”字段模式在进行更新时按预期保存日期/用户 ID。但是,它在 notes 上失败了架构:
SimpleSchema invalid keys for "blablabla" context:
0: Object
  name: "note.0.updates.0.at"
  type: "keyNotInSchema"
  value: Mon May 11 2015 11:57:58 GMT-0400 (Eastern Daylight Time)
1: Object
  name: "note.0.updates.0.user_id"
  type: "keyNotInSchema"
  value: "abcd1234"

我相信“名称”应该看起来像“people.note.0.updates.0.at”,但我不确定这个假设是否正确,我完全不确定如何实现这一点。

更新:

用于更新的代码 people
  {{#autoForm collection="people" id=formId type="update" class="update" autocomplete="off" doc=getDocument autosave=true template="quickform"}}
  {{> afQuickField name='note' template="quickform" }}
  {{/autoForm}}
formId返回一个随机的 ID 字符串和 getDocument通过正确的集合。
Schemas.notes._schemaKeys不列出atuser_id字段...但是 Schemas.people._schemaKeys做。

人物模式显示: [..., "updates.$.at", "updates.$.user_id", ...]

Notes 架构显示:["note", "updates", "updates.$"]

多么奇怪。

最佳答案

问题在于模式声明的顺序。我认为哪个有意义?我在“更新”之前声明“注释”,最后声明“人”。先把“更新”彻底解决了这个问题。

我将把这作为一个可能的错误报告给集合 repo 。

关于meteor - 带有嵌套 autoValue 的 SimpleSchema 无效键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30172615/

相关文章:

javascript - 在 Meteor 1.3.x 中,如何从 imports/api 中添加一个集合?

meteor - 如何在 Meteor 提供的服务器中设置环境变量?

Oracle:是否可以为模式创建同义词?

postgresql - 在 Postgres 中 GRANT/REVOKE 时限制模式的范围

meteor - 如何知道用户文档何时加载到 Meteor Accounts 中

meteor - 如何在 Meteor 中包含额外的时刻区域设置

Xml 模式唯一性不检查唯一性

SQLite 查询查找主键

javascript - 使用 Meteor 将数据从服务器流式传输到客户端 :

oneOf 对象的 Json Schema 示例