Files
meanTorrent/app/models/article.js
2013-12-25 16:36:33 +02:00

51 lines
814 B
JavaScript

'use strict';
/**
* Module dependencies.
*/
var mongoose = require('mongoose'),
Schema = mongoose.Schema;
/**
* Article Schema
*/
var ArticleSchema = new Schema({
created: {
type: Date,
default: Date.now
},
title: {
type: String,
default: '',
trim: true
},
content: {
type: String,
default: '',
trim: true
},
user: {
type: Schema.ObjectId,
ref: 'User'
}
});
/**
* Validations
*/
ArticleSchema.path('title').validate(function(title) {
return title.length;
}, 'Title cannot be blank');
/**
* Statics
*/
ArticleSchema.statics.load = function(id, cb) {
this.findOne({
_id: id
}).populate('user', 'name username').exec(cb);
};
mongoose.model('Article', ArticleSchema);