'use strict';
module.exports = app => {
const mongoose = app.mongoose;
const Schema = mongoose.Schema;
const EventSchema = new Schema({
type: { type: String },
openid: { type: String },
data: { type: Object },
dateCreated: { type: Date },
equipment: { type: Schema.Types.ObjectId, ref: 'Equipment' },
});
EventSchema.methods.getItem1 = (_id, ctx) => {
return ctx.model.Event.findById(_id);
};
EventSchema.statics.getItem2 = (_id, ctx) => {
return ctx.model.Event.findById(_id);
};
const Event = mongoose.model('Event', EventSchema, null, { cache: false });
return Event;
};
这里的getItem1 / getItem2 方法在service中该如何调用?
回复 (2)
K
搜了半天没搜到例子,希望可以得到老哥们的解答。
M
getItem1、getItems2这些操作不是应该放到service中操作么?如果你想这样操作,应该挂到Event上吧
参与回复
登录后即可参与回复。登录