mardi 23 juin 2015

Meteor Collections and when to use a schema

I am starting to build an app and have a collection that is used to create a pet post.

Note: I'm using the following packages to build my collection schemas, Simple Schema http://ift.tt/1s3s31O

The page that I'm using to insert the data into this particular collection has a section that based on the choice the user makes they are presented with more options.

For example focusing in on one question there are some checkboxes, by default none are selected but if the user selects any checkbox they are given more options to choose from either via checkboxes or text areas. The point is that they will have additional options to choose from based on their selection.

I think the best way to handle how the data is inserted is via the template helpers for that specific section so that's not the question.

Instead where i'm confused is at the collection level and how to Schema that information or if I even need to.

For example let's say you have a question that involves pets.

The question could be: Do you have pets?

The checkbox options could be:

  1. Dogs
  2. Cats
  3. Other

By default all of these checkboxes are unchecked but if the user checks any of the boxes then a text area is revealed (again i realize all of this happens at the Template.events and Template.helpers level).

What my real question is, now that I've set the scenario, is how do you store information like that or schema it to allow these kinds of values.

Assuming that all of the functions to grab this data are all on the Template.helpers level so this is simple a question about how to store kind of data in this scenario.

My notion was to do something like this (using the simpleSchema package):

Pet = new SimpleSchema({
 petInstructions: {
  type: String,
  optional: true,
  allowedValues: ['Dogs', 'Cats', 'Other']    
 }
});

However I'm not certain this is right again let me re-iterate that I do want the checkboxes to have the values 'Dogs', 'Cats', 'Other' and the text area when any of these are checked so that the end-user can enter more information about their pets.

What i'm unclear about is if I'm thinking about how this data's Schema could be or how this kind of information should be stored in the MongoDB.

I feel like there should also be a property for the TextArea input, would that be a good way to think about it?

For example (adding on to the example above):

Pet = new SimpleSchema({
     petInstructions: {
      type: String,
      optional: true,
      allowedValues: ['Dogs', 'Cats', 'Other'],
      textArea: ""
     }
    });

Should I just leave another property/value for that particular content?

This is somewhat of a granular level question that understanding something simple like this would help clarify other questions I had.

Thank you.




Aucun commentaire:

Enregistrer un commentaire