relationStudentCoach.js 953 B

12345678910111213141516171819202122
  1. 'use strict';
  2. const Schema = require('mongoose').Schema;
  3. const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
  4. // 学员与教练关系表
  5. const relationStudentCoach = {
  6. student_id: { type: String, required: true, zh: '学生id', ref: 'Student', getProp: [ 'name' ] }, //
  7. coach_id: { type: String, required: true, zh: '教练id', ref: 'Coach', getProp: [ 'icon', 'name', 'phone', 'age', 'gender', 'level', 'honor' ] }, //
  8. doc: { type: Object, required: false, zh: '档案' }, //
  9. config: { type: Object, required: false, zh: '设置' }, //
  10. };
  11. const schema = new Schema(relationStudentCoach, { toJSON: { virtuals: true } });
  12. schema.index({ id: 1 });
  13. schema.index({ 'meta.createdAt': 1 });
  14. schema.index({ student_id: 1 });
  15. schema.index({ coach_id: 1 });
  16. schema.plugin(metaPlugin);
  17. module.exports = app => {
  18. const { mongoose } = app;
  19. return mongoose.model('RelationStudentCoach', schema, 'relationStudentCoach');
  20. };