In einem „afterRemote“ -Haken bestehende i ein bestimmtes Modell finden möge, und ein Attribut ändern:Loopback: PersistedModel.findById() gibt nicht die letzte Instanz. Methoden wie save() nicht
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
});
Wie kann ich das gefundene Einheit manipulieren und speichern? Save() - Methode ist nicht vorhanden. Alles in allem liefert findById ein reines JSON-Objekt, keine echte PersistedModel-Instanz.
Das Modell wurde wie folgt definiert:
{ "name": "message", "base": "PersistedModel", "strict": false, "idInjection": false, "options": { "validateUpsert": true },
Datenbank ein mongoDB ist.
'findById' muss tatsächlich eine Modellinstanz zurückgeben. http://apidocs.strongloop.com/loopback/#persistedmodel-findbyid Sie sollten wahrscheinlich einen Fehler hier protokollieren: https://github.com/strongloop/loopback/issues/new – Sterex
Ah, sieht aus wie du hast - https://github.com/strongloop/loopback/issues/3521 :) – Sterex