如何在bookshelf.js中保存多个记录。
如何不循环和插入保存以下数据
[
{name: 'Person1'},
{name: 'Person2'}
]发布于 2016-03-28 13:16:19
var Promise = require('bluebird');
var Accounts = bookshelf.Collection.extend({
model: Account
});
var accounts = Accounts.forge([
{name: 'Person1'},
{name: 'Person2'}
])
Promise.all(accounts.invoke('save')).then(function() {
// collection models should now be saved...
});请参阅注释: Invoke现在已被invokeThen取代
accounts.invokeThen('save').then(function() {
// ... all models in the collection have been saved
});发布于 2016-12-14 14:26:44
我认为Book大陆架已经被更新,将'invoke‘替换为'invokeThen’。
var Accounts = bookshelf.Collection.extend({
model: Account
});
var accounts = Accounts.forge([
{name: 'Person1'},
{name: 'Person2'}
])
accounts.invokeThen('save').then(function() {
// ... all models in the collection have been saved
});
发布于 2019-07-14 02:17:45
我试着用invokeThen对case进行跟踪,但在我的案例中失败了。似乎我们可以使用模型本身而不必创建单独的集合instance.Here,Employee是一个模型而不是单独的集合对象。
Employee.collection()
.add(employees)
.invokeThen('save');https://stackoverflow.com/questions/36263191
复制相似问题