'use strict'; const Schema = require('mongoose').Schema; const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin'); // 赛事场地 const match_address = { belong_id: { type: String, required: true, zh: '归属id', ref: 'Race.User', getProp: [ 'name' ] }, // 用户表中的名称 name: { type: String, required: true, zh: '名称' }, // remark: { type: String, required: false, zh: '备注' }, // is_use: { type: String, required: false, default: '0', zh: '是否使用' }, // 0:启用,1:禁用 }; const schema = new Schema(match_address, { toJSON: { getters: true, virtuals: true } }); schema.index({ id: 1 }); schema.index({ 'meta.createdAt': 1 }); schema.index({ belong_id: 1 }); schema.index({ name: 1 }); schema.plugin(metaPlugin); const source = 'race'; module.exports = app => { const is_multiple = app.mongooseDB.clients; let model; if (is_multiple) { const conn = app.mongooseDB.get(source); model = conn.model('MatchAddress', schema, 'matchAddress'); } else { const { mongoose } = app; model = mongoose.model('MatchAddress', schema, 'matchAddress'); } return model; };