Q:

Mongoose MissingSchemaError with Mocha test

I'm trying to use mocha to test my API, but it fails with an Uncaught MissingSchemaError: Schema hasn't been registered for model "Kitchen".
Use mongoose.model(name, schema) every time I call a method on the model that uses populate(field).
Minimal example: https://gist.github.com/connors511/6204164 (transaction.js being the offender)      
I've also tried using the method as a schema.statics, but it returns the same result as the example.
If I remove the populate('where.kitchen') from the _listForUserClub method, it fails for MissingSchema Club instead.
Any idea what's causing this, or how to fix it?

A:

I've fixed the issue by using
var _model;
try {
    _model = mongoose.model('ClubTest', _schema);
    _model.singular = 'clubtest';
} catch(e) {
    _model = mongoose.model('ClubTest');
}

instead of
var _model = mongoose.model('ClubTest', _schema);
_model.singular = 'clubtest';

for all my models after finding the workaround at https://groups.google.com/d/msg/mongoose-orm/PXTjqqpaDFk/tYx1ge04GlsJ

