123456789101112131415161718192021222324252627282930 |
- 'use strict';
- const Schema = require('mongoose').Schema;
- const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
- const { ObjectId } = require('mongoose').Types;
- const source = 'race';
- // 表
- const race = {
- title: { type: String, zh: '比赛名称' },
- user: { type: String, zh: '用户', ref: 'base.User', getProp: [ 'name' ] },
- ground: { type: String, zh: '场地', ref: 'Ground', getProp: [ 'name' ] },
- player: { type: String, zh: '选手', refPath: 'player_from', getProp: [ 'name' ] },
- player_from: { type: String, zh: '选手数据来源' },
- remark: { type: String },
- };
- const schema = new Schema(race, { toJSON: { virtuals: true } });
- schema.index({ id: 1 });
- schema.index({ 'meta.createdAt': 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('Race', schema, 'race');
- } else {
- const { mongoose } = app;
- model = mongoose.model('Race', schema, 'race');
- }
- return model;
- };
|