relationStudentSchool.js 1.1 KB

1234567891011121314151617181920212223242526
  1. 'use strict';
  2. const Schema = require('mongoose').Schema;
  3. const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
  4. // 学生档案
  5. const doc = {
  6. is_past: { type: String, default: '0' }, // 往期学员: 0-当期;1-往期
  7. term: { type: String }, // 学期
  8. };
  9. // 学员与学校关系表
  10. const relationStudentSchool = {
  11. student_id: { type: String, required: false, zh: '学员id', ref: 'Student', getProp: [ 'name', 'icon', 'level', 'phone' ] }, //
  12. school_id: { type: String, required: false, zh: '学校id', ref: 'School', getProp: [ 'img_url', 'name', 'phone', 'coach_num', 'student_num', 'address', 'brief' ] }, //
  13. doc: { type: Object, required: false, zh: '档案' }, //
  14. };
  15. const schema = new Schema(relationStudentSchool, { toJSON: { virtuals: true } });
  16. schema.index({ id: 1 });
  17. schema.index({ student_id: 1 });
  18. schema.index({ school_id: 1 });
  19. schema.index({ 'meta.createdAt': 1 });
  20. schema.plugin(metaPlugin);
  21. module.exports = app => {
  22. const { mongoose } = app;
  23. return mongoose.model('RelationStudentSchool', schema, 'relationStudentSchool');
  24. };