1
使用下面的JSON一次:如何保存多個寄存器上bookshelf.js
{
"name" : "Teste",
"username" : "teste1",
"password" : "teste1",
"email" : "[email protected]",
"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
?
謝謝。