Created
March 27, 2015 18:56
-
-
Save danared/9d5a3fdaab4f6f9ce2c6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var bandSchema = new mongoose.Schema({ | |
name: String, | |
lead: { type: mongoose.Schema.Types.ObjectId, ref: 'person' } | |
}); | |
var autoPopulateLead = function(next) { | |
this.populate('lead'); | |
next(); | |
}; | |
bandSchema. | |
pre('findOne', autoPopulateLead). | |
pre('find', autoPopulateLead); | |
var Band = mongoose.model('band', bandSchema, 'bands'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why don't you pass
next
as second parameter ofthis.populate('lead');
(L7)?