SimpleSchema Invalid definition for tags field error


#1

Can someone please help me understand why the tags field is invalid?

    var Schemas = {};

Schemas.Questions = new SimpleSchema({
  text: {
    type: String,
    label: "Text"
  },
  choices: {
    type: [String],
    label: "Choices",
    minCount: 4,
    maxCount: 4
  },
  correctChoice: {
    type: Number,
    label: "Correct Choice",
    min: 0,
    max: 3
  },
  tags: {
    type: [Schemas.Tags],
    label: "Tags",
    minCount: 1,
    autoForm: {
      options: function() {
        return Tags.find().map(function(t){
          return {label: t.name, value: t._id};
        });
      }
    }
  },
  statistics: {
    type: Schemas.QuestionStatistics,
    label: "Statistics",
    optional: true
  }
});

Schemas.Tags = new SimpleSchema({
  name: {
    type: String,
    label: "Tag Name"
  },
  correct: {
    type: Number,
    label: "Correct",
    min: 0,
    autoValue: Schemas.zeroOrInc
  },
  wrong: {
    type: Number,
    label: "Wrong",
    min: 0,
    autoValue: Schemas.zeroOrInc
  }
});

The Tags collection is defined and I have a fixtures files that loads some example Tags into the collection. The console says the error is at the line that says
Schemas.Questions = new SimpleSchema({

Thank you so much for reading and helping. Sorry if this is a noob question.


#2

Schemas.Tags is not defined when you use it in Schemas.Questions . Move the tag definition before the questions definition.


#3

Nope. I reordered the order of initialization, and it still gives me the same error. =\


#4

well, that var Schemas = {} create empty object without any Tags property.
if your pasted code is accurate.


#5

Oh, well there is actually a separate Schemas file. I think it has something to do with the autoform function. There is really too much code to post it here. I will comment out more and more code as I try to zero in on the problem and report back here if I learn anything. Sorry for the confusion and thanks for the advice. =)


#6

Sorry I should have been more explicit, you are using the Tags collection in the Autoform function, you need to make sure that this is defined and has an attached schema before you can use it like this.