Skip to content

Instantly share code, notes, and snippets.

@mekhami
Last active February 27, 2016 19:28
Show Gist options
  • Select an option

  • Save mekhami/d84718862cbfea584ca5 to your computer and use it in GitHub Desktop.

Select an option

Save mekhami/d84718862cbfea584ca5 to your computer and use it in GitHub Desktop.
/home/lvanderpool/Projects/angular-wedding/node_modules/mongoose/lib/utils.js:419
throw err;
^
TypeError: object is not a function
at model.RsvpSchema.virtual.set.unconfirmed (/home/lvanderpool/Projects/angular-wedding/models/rsvp.js:22:2)
at model.EventEmitter.emit (events.js:117:20)
at handleSave (/home/lvanderpool/Projects/angular-wedding/node_modules/mongoose/lib/model.js:129:10)
at /home/lvanderpool/Projects/angular-wedding/node_modules/mongoose/lib/utils.js:414:16
at /home/lvanderpool/Projects/angular-wedding/node_modules/mongoose/node_modules/mongodb/lib/mongodb/collection.js:347:9
at Server.Base._callHandler (/home/lvanderpool/Projects/angular-wedding/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/base.js:382:41)
at /home/lvanderpool/Projects/angular-wedding/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:472:18
at MongoReply.parseBody (/home/lvanderpool/Projects/angular-wedding/node_modules/mongoose/node_modules/mongodb/lib/mongodb/responses/mongo_reply.js:68:5)
at null.<anonymous> (/home/lvanderpool/Projects/angular-wedding/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:430:20)
at EventEmitter.emit (events.js:95:17)
var mongoose = require('mongoose');
var ExtraSchema = new mongoose.Schema({
name: String,
});
var Extra = mongoose.model('Extra', ExtraSchema);
var RsvpSchema = new mongoose.Schema({
code: {type: String, unique: true, dropDups: true},
name: {type: String, unique: true, dropDups: true},
email: String,
allowed_extras: Number,
extras: [ExtraSchema],
attending: {type: Boolean, default: false}
});
RsvpSchema.post('save', function(next) {
for (i=0; i<this.allowed_extras; i++) {
this.extras.push(Extra.create({ name: ''}))
}
next();
});
RsvpSchema.virtual('confirmed_extras').get(function() {
var unconfirmed = 0;
for (extra in this.extras) {
if (!extra.name) {
unconfirmed += 1
}
};
return this.allowed_extras - unconfirmed
});
RsvpSchema.set('toJSON', {
virtuals: true
});
RsvpSchema.set('toObject', {
virtuals: true
});
module.exports = mongoose.model('RSVP', RsvpSchema);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment