在处理程序中创建但未返回的Promise

时间:2016-03-14 14:17:39

标签: node.js controller sails.js

自从我将sails.js更新为版本0.12.0后,出现了此警告:

Warning: a promise was created in a handler but was not returned from it
at Deferred.toPromise (K/trunk/node_modules/waterline/lib/waterline/query/deferred.js:494:61)
at Deferred.then (K/trunk/node_modules/waterline/lib/waterline/query/deferred.js:505:15)

它发生在从模型中获取信息的控制器中,然后需要更新模型中的条目。

ExampleModel.findOne()
..
.then(function (){
   ExampleModel.update({id:nid},{amount:newamount})
   .then(function (updates){
      return.json(updates);
   }

我不确定如何解决这个问题?这只是一个警告,但想解决它。

1 个答案:

答案 0 :(得分:3)

试试这个:

ExampleModel.findOne()
  .then(function (){
     return ExampleModel.update({id:nid},{amount:newamount})
       .then(function (updates){
          return.json(updates);
       }