是的,我已阅读Mongoose populate after save,但我仍然无法将这些内容与承诺放在一起。
我已经尝试过在pushComment()中使用.populate的各种不同方式,我能想到的,似乎无法正确使用。非常感谢任何帮助,谢谢。
端点
set_include_path(getcwd().'/vendor/primal/color/lib/Primal/Color/');
include 'Color.php';
include 'Parser.php';
include 'RGBColor.php';
include 'HSVColor.php';
$hello = Primal\Color\Parser::parse('#666');
var_export($hello->toHSV());
/*
returns
Primal\Color\HSVColor::__set_state(array(
'hue' => 0,
'saturation' => 0,
'value' => 37.647058823529413,
'alpha' => 1,
))
*/
pushComment
export function addComment(req, res) {
let newComment = {
author: req.user._id,
body: req.body.comment,
date: new Date()
};
return Deal.findById(req.params.id)
.exec()
.then(handleEntityNotFound(res))
.then(pushComment(newComment))
.then(respondWithResult(res))
.catch(handleError(res));
}
respondWithResult
function pushComment(comment) {
return function (entity) {
entity.comments.push(comment);
return entity.populate('author').save()
.then(updated => {
return updated
});
};
}