I'll explain myself.
We have something like
var UserSchema = new Schema({
issuedOffers: [ UserOfferSchema ]
});
var UserOfferSchema = new Schema({
offer: { type: ObjectId, ref: 'Offer' },
issuedAt: Date,
validatedAt: Date,
status: Number
});
When trying to make populate with this query
User
.find({})
.populate('issuedOffers')
.exec(function(err, users) {
console.log(users);
test.equal(10,10);
test.done();
});
I get this error
MissingSchemaError: Schema hasn't been registered for model "undefined".
Use mongoose.model(name, schema)
I don't know if I'm doing something wrong or It just cannot be populated.
And yes, they all have been registered.
For those who came here I found the solution :)
You need a reference between the 2 schemata.
e.g. in your UserOfferSchema:
user: { type: mongoose.Schema.Types.ObjectId, ref: 'User' }