如何在bookhelf.js上一次保存多个寄存器

使用下面的json:

{ "name" : "Teste", "username" : "teste1", "password" : "teste1", "email" : "teste2@teste", "photo" : "teste", "description" : "teste", "company_posts" : [ {"text": "Oi"}, {"text": "olá"} ] } 

和下面的代码:

  company_posts = req.body.company_posts delete req.body.company_posts bookshelf.Model.extend({ tableName: 'companies' }).forge().save(req.body).then(function(company){ for(var prop in company_posts){company_posts[prop].company_id = company.id} bookshelf.Model.extend({ tableName: 'companies_posts' }).forge().save(company_posts).then(function(company_posts){ res.send(company_posts) }) }) 

服务器返回我:

 Unhandled rejection Error: ER_WRONG_VALUE_COUNT_ON_ROW: Column count doesn't match value count at row 1 

怎么了? 如果我尝试插入company_posts[0]它的作品。

我如何一次插入所有company_posts

谢谢。

我的错误是试图使用Model而不是一个Collection

代替:

 bookshelf.Model.extend({ tableName: 'companies_posts' // where I use forge() instead of collection() }).forge().save(company_posts).then(function(company_posts){ res.send(company_posts) }) 

这工作正常:

 bookshelf.Model.extend({ tableName: 'companies_posts' //where I use collection() and works fine }).collection(company_posts).invokeThen('save').then(function(company_posts){ res.send(company_posts) })