在“afterRemote” -hook我想找到一个特定的模式,改变属性:Loopback:PersistedModel.findById()不提供最终实例。像保存方法()不存在
Team.afterRemote('prototype.__create__messages', function(ctx, message, next) {
var Message = Team.app.models.message;
// Promises.all not required, just for debugging (i removed other code)
const promises = Promise.all([
Message.findById(message.id),
])
promises.then(function(result) {
console.log("FOUND Message ", result);
// here i'd like to change an attribute and save the model back to database
console.log(typeof result.save); // will print undefined
});
我怎么能操纵发现实体和保存呢?保存() - 方法不存在。总而言之,findById提供了一个普通的JSON对象,而不是一个真正的PersistedModel实例。
模型被定义为:
{ "name": "message", "base": "PersistedModel", "strict": false, "idInjection": false, "options": { "validateUpsert": true },
数据库是一个MongoDB的。
'findById'实际上必须返回一个模型实例。 http://apidocs.strongloop.com/loopback/#persistedmodel-findbyid你应该在这里记录一个bug:https://github.com/strongloop/loopback/issues/new – Sterex
啊,看起来像你有 - https:/ /github.com/strongloop/loopback/issues/3521 :) – Sterex