This repository was archived by the owner on Aug 30, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +3
-20
lines changed
Expand file tree Collapse file tree 2 files changed +3
-20
lines changed Original file line number Diff line number Diff line change @@ -88,7 +88,7 @@ exports.list = function(req, res) {
8888 * Article middleware
8989 */
9090exports . articleByID = function ( req , res , next , id ) {
91- Article . load ( id , function ( err , article ) {
91+ Article . findById ( id ) . populate ( 'user' , 'displayName' ) . exec ( function ( err , article ) {
9292 if ( err ) return next ( err ) ;
9393 if ( ! article ) return next ( new Error ( 'Failed to load article ' + id ) ) ;
9494 req . article = article ;
Original file line number Diff line number Diff line change @@ -17,7 +17,8 @@ var ArticleSchema = new Schema({
1717 title : {
1818 type : String ,
1919 default : '' ,
20- trim : true
20+ trim : true ,
21+ required : 'Title cannot be blank'
2122 } ,
2223 content : {
2324 type : String ,
@@ -30,22 +31,4 @@ var ArticleSchema = new Schema({
3031 }
3132} ) ;
3233
33- /**
34- * Validations
35- */
36- ArticleSchema . path ( 'title' ) . validate ( function ( title ) {
37- return title . length ;
38- } , 'Title cannot be blank' ) ;
39-
40- /**
41- * Statics
42- */
43- ArticleSchema . statics = {
44- load : function ( id , cb ) {
45- this . findOne ( {
46- _id : id
47- } ) . populate ( 'user' , 'displayName' ) . exec ( cb ) ;
48- }
49- } ;
50-
5134mongoose . model ( 'Article' , ArticleSchema ) ;
You can’t perform that action at this time.
0 commit comments