评论回调方法提取用户名
exports.detail=function(req,res){
var id=req.params.id
Movie.findById(id,function(err,movie){
Comment.find({movie: id},function(err,comments){
console.log(comments)
res.render('detail',{
title:movie.title,
movie:movie,
comments:comments
// {title:'momo',
// country:'USA',
// year:'2014',
// flash:'http://www.imooc.com/video/1226/0',
// summary:'你好试试'}
})
})
})
}
使用populate获取用户名
exports.detail=function(req,res){
var id=req.params.id
Movie.findById(id,function(err,movie){
Comment.find({movie: id})
.populate('from','name')
.exec(function(err,comments){
console.log(comments)
res.render('detail',{
title:movie.title,
movie:movie,
comments:comments
// {title:'momo',
// country:'USA',
// year:'2014',
// flash:'http://www.imooc.com/video/1226/0',
// summary:'你好试试'}
})
})
})
}
与其有关联的对象设置为replay
comment中初始化: movie,from.,replay,mata,content,to
修改to为
replay:{
from:{type:ObjectId,ref:'User'},
to:{type:ObjectId,ref:'User'},
content:String
},
在jade文件中对用户图片添加锚点#comments