From 334cdccec27afcb1a353df49f7edb77181048843 Mon Sep 17 00:00:00 2001 From: Dennis Eriksen Date: Tue, 30 Apr 2013 12:25:44 +0200 Subject: made a function for returning project by ID --- models/project.js | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'models') diff --git a/models/project.js b/models/project.js index 2424694..2641fe5 100644 --- a/models/project.js +++ b/models/project.js @@ -6,12 +6,8 @@ var mongoose = require('mongoose') , Schema = mongoose.Schema; - - - - var ProjectSchema = new Schema({ - user: { type: String, ref: 'User' }, + user: { type: Schema.ObjectId, ref: 'User' }, name: { type: String, default: '', trim: true }, description: {type: String, default: '', trim: true }, currency: { type: String, default: 'kr', trim: true }, @@ -20,7 +16,6 @@ var ProjectSchema = new Schema({ updated: { type: Date, default: Date.now } }); - // the four validations below only apply if you are signing up traditionally ProjectSchema.path('name').validate(function(name) { @@ -28,12 +23,29 @@ ProjectSchema.path('name').validate(function(name) { return name.length; }, 'Project name cannot be blank'); -ProjectSchema.methods = { +ProjectSchema.statics = { log: function() { console.log('wat. wat logged this'); + }, + + + + /** + * Find project by id + * + * @param {ObjectId} id + * @param {Function} callback + * @api private + */ + + load: function(id, callback) { + this.findOne({ _id: id }) + .populate('user') + .exec(callback); } + } mongoose.model('Project', ProjectSchema); -- cgit v1.2.3