使用Bookshelf.js执行更新后提取数据

我正在使用save()方法(Bookshelf.js)来更新PostgreSQL中的数据。 我想在更新后获取完整的模型(所有列),我该怎么做? 在我看来, save()方法只返回id和更新的列。 我可能会做错了,所以任何指导将不胜感激。 谢谢。

在Sequelizejs中,我们使用这种方法,只要在操作执行成功的时候调用你的函数就可以了。你可以在这里试试

 new Author({id: 1, first_name: 'User'}) .save({bio: 'Short user bio'}, {patch: true}) .then(function(model) { //two approach //try this but not sure work in Bookshelf or not return model.fetchAll(); //or u can try new Article().fetchAll() .then(function(articles) { res.send(articles.toJSON()); }).catch(function(error) { res.send('An error occured'); }); }); 

.save()书架方法返回attributes字段中的更新对象。

 new User().save({ firstname: 'Foo', lastname: 'Bar' }) .then(data => { console.log(data.attributes); // You can also do this to remove Bookshelf Model methods data = data.toJSON(); console.log(data); });