モデルを定義する前にモデルが必要な状況に遭遇しました。で、モデルを取得someMethod()
しようとしました。this.model('Goods')
何か良い方法はないかと考えました。
var mongoose = require('mongoose')
, GoodsSchema = require('./schemas').GoodsSchema
, GoodsModel;
GoodsSchema.methods.someMethod = function () {
// need GoodsModel here
// GoodsModel.find()....
};
GoodsModel = mongoose.model('Goods', GoodsSchema);
module.exports = GoodsModel;