具有不同架构的对象的简单架构数组

时间:2019-09-10 22:26:09

标签: meteor schema meteor-autoform

学生模式具有一组管理的对象(测试)。没有两个测试是相同的,一个学生可以进行多个测试。需要能够插入/更新具有不同架构的[test]对象的数组。

曾尝试将每个测试放入自己的“收藏夹”中,以回溯到学生ID,但是有数百个独特的测试产生了数百个收藏夹。最佳做法?

const StudentSchema = new SimpleSchema({
lname: {
        type: String,
        optional: false,
        label: "Last Name",
        max: 100
    },
fname: {
        type: String,
        optional: false,
        label: "First Name",
        max: 100
    },
tests: {
        type: Object,
        blackbox: true,
        optional: true,
    },
}, { tracker: Tracker });

//Tests Schema example 1------------------------

TestADT_Schema = new SimpleSchema({

total_ADT_score_rs: {type: Number, optional: true,},
total_ADT_score_tsc: {type: Number, optional: true,},
qualitative_score: {type: Number, optional: true,},
});

Test_ADT_Schema.attachSchema(ADT_Schema);

//Test Schema example 2 --------------------------

TestWJIVCA_Schema = new SimpleSchema({

GenIntellectualAbility_AE: {type: Number, optional: true,},
  GenIntellectualAbility_GE: {type: Number, optional: true,},
  GenIntellectualAbility_RPI: {type: Number, optional: true,},
  GenIntellectualAbility_SS: {type: Number, optional: true,},
  GFGC_COMPOSITE_AE: {type: Number, optional: true,},
  GFGC_COMPOSITE_GE: {type: Number, optional: true,},
  GFGC_COMPOSITE_RPI: {type: Number, optional: true,},
});

TestWJIVCA_Schema.attachSchema(TestsWJIVCASchema);

每个学生拥有1到n个测验,需要将测验嵌套到学生的收藏夹中,但不确定是否可以这样做?

1 个答案:

答案 0 :(得分:2)

如果测试是一个包含神秘对象的数组,则应将tests标记为数组,并将其子项标记为黑盒对象:

const StudentSchema = new SimpleSchema({
lname: {
        type: String,
        optional: false,
        label: "Last Name",
        max: 100
    },
fname: {
        type: String,
        optional: false,
        label: "First Name",
        max: 100
    },
tests: Array,
'tests.$': {
        type: Object,
        blackbox: true,
    },
}, { tracker: Tracker });