Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

Commit

Permalink
Article Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
amoshaviv committed Apr 2, 2014
1 parent 47561ce commit c11c428
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 20 deletions.
2 changes: 1 addition & 1 deletion app/controllers/articles.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ exports.list = function(req, res) {
* Article middleware
*/
exports.articleByID = function(req, res, next, id) {
Article.load(id, function(err, article) {
Article.findById(id).populate('user', 'displayName').exec(function(err, article) {
if (err) return next(err);
if (!article) return next(new Error('Failed to load article ' + id));
req.article = article;
Expand Down
21 changes: 2 additions & 19 deletions app/models/article.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ var ArticleSchema = new Schema({
title: {
type: String,
default: '',
trim: true
trim: true,
required: 'Title cannot be blank'
},
content: {
type: String,
Expand All @@ -30,22 +31,4 @@ var ArticleSchema = new Schema({
}
});

/**
* 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', 'displayName').exec(cb);
}
};

mongoose.model('Article', ArticleSchema);

1 comment on commit c11c428

@mgenev
Copy link

@mgenev mgenev commented on c11c428 Apr 7, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are you moving away from using the static?

Please sign in to comment.