'use strict'; const Schema = require('mongoose').Schema; const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin'); const source = 'race'; // 赛事组别 const match_group = { match_id: { type: String, required: true, zh: '赛事id', ref: 'Race.Match', getProp: [ 'name' ] }, // 比赛信息中的比赛名称 name: { type: String, required: true, zh: '名称' }, // age: { type: String, required: false, zh: '年龄限制' }, // 12-16 / null(不限) explain: { type: String, required: false, zh: '说明' }, // }; const schema = new Schema(match_group, { toJSON: { getters: true, virtuals: true } }); schema.index({ id: 1 }); schema.index({ 'meta.createdAt': 1 }); schema.index({ match_id: 1 }); schema.index({ name: 1 }); schema.plugin(metaPlugin); module.exports = app => { const is_multiple = app.mongooseDB.clients; let model; if (is_multiple) { const conn = app.mongooseDB.get(source); model = conn.model('MatchGroup', schema, 'matchGroup'); } else { const { mongoose } = app; model = mongoose.model('MatchGroup', schema, 'matchGroup'); } return model; };