Closed nmcclay closed 8 years ago
Great idea - I'll put a more complete example together + some Chai tests when I have a minute. In the interim, can you show me the specific code you're using to invoke mongoose-seed?
Best, Sean
@nmcclay there's a pretty good example in the readme - was there anything else you were looking for?
Hi guys, I had the same problem , but I added a little modification in the library and solved my problem. let me show you.
My schema export a function
module.exports = () => {
var schema = Schema({
name: {
type: String,
required: true
}
});
return mongoose.model('ProfileType', schema);
};
in library I needed check if model was a function
Seeder.prototype.loadModels = function(modelPaths) {
console.log(modelPaths);
modelPaths.forEach(function(modelPath) {
**var model = require(path.resolve(modelPath));
if (typeof model === 'function') {
model();
}**
});
};
What do you think about this solution ?
This looks great - submit a PR and we'll get it into the codebase!
Thanks to @alanhr for setting up some unit tests in pr #8 - closing issue
I tried for about an hour to figure out how to get mongoose-seed to see my shema but for whatever reason it is refusing to work:
I'm assuming this is a different approach to setting up your mongoose model than you are using in your example, but I can't really tell because of the lack of samples or tests :(