Skip to content

Instantly share code, notes, and snippets.

@aheckmann
Created February 17, 2012 14:49
Show Gist options
  • Save aheckmann/1853895 to your computer and use it in GitHub Desktop.
Save aheckmann/1853895 to your computer and use it in GitHub Desktop.
schema.virtual('magic').set(function (v) {
this.magic = v;
});
schema.pre('save', function (next) {
if (!this.magic) return next();
this.model('Other')
.findOne({ magic: this.magick }).select('_id').exec(function (err, other) {
if (err || !other) return next(err);
self._owner = other._id;
next();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment