Skip to content
This repository has been archived by the owner on Jan 3, 2023. It is now read-only.

Handle Mongoose model intitialization errors #455

Merged
merged 1 commit into from
Jul 20, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion generators/service/templates/js/model/mongoose.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,11 @@ module.exports = function (app) {
timestamps: true
});

return mongooseClient.model('<%= camelName %>', <%= camelName %>);
// This is necessary to avoid model compilation errors in watch mode
// see https://github.com/Automattic/mongoose/issues/1251
try {
return mongooseClient.model('<%= camelName %>');
} catch (e) {
return mongooseClient.model('<%= camelName %>', <%= camelName %>);
}
};