ForestAdmin/toolbelt

View on GitHub
src/services/dumpers/templates/forest-express/models/mongo-model.hbs

Summary

Maintainability
Test Coverage
// This model was generated by Forest CLI. However, you remain in control of your models.
// Learn how here: https://docs.forestadmin.com/documentation/reference-guide/models/enrich-your-models

module.exports = (mongoose, Mongoose) => {
  // This section contains the properties of your model, mapped to your collection's properties.
  // Learn more here: https://docs.forestadmin.com/documentation/reference-guide/models/enrich-your-models#declaring-a-new-field-in-a-model
  const schema = Mongoose.Schema({
  {{#each fields as |field|}}
    {{wsc field.name}}: {{#if field.ref}}{ type: {{field.type}}, ref: '{{field.ref}}' }{{else if (isObject field.type)}}{{>renderNested type=field.type level=2}}{{else}}{{field.type}}{{/if}},
  {{/each}}
  }, {
    timestamps: {{timestamps}},
  });

  return mongoose.model('{{modelName}}', schema, '{{table}}');
};