我有这样的事情
[{
"id":"3",
"clientName":"John Doe",
"address":"street, 15",
"latitude":"50.1212",
"longitude":"30.1111",
"timeFrom":"2017-04-05T14:48:00.000Z",
"timeTo":"2017-04-05T15:48:00.000Z",
"comments":"call before delivery"
}]
这是我模特的一部分:
Order = sequelize.define('Order', {
latitude: {
type: DataTypes.FLOAT,
allowNull: false,
defaultValue: null,
validate: {
min: -90,
max: 90
}
},
longitude: {
type: DataTypes.FLOAT,
allowNull: false,
defaultValue: null,
validate: {
min: -180,
max: 180
}
},
{
classMethods: {
associate: function (models) {
Order.belongsTo(models.User);
}
}
});
return Order;
如何通过Sequalize.js编写对象数组?如果我试图写对象,它会通过,但是[{},{}]会遇到麻烦
答案 0 :(得分:0)
您想要从.bulkCreate()开始 - http://docs.sequelizejs.com/en/v3/docs/instances/#working-in-bulk-creating-updating-and-destroying-multiple-rows-at-once
只要对象中的键与列名匹配,它就可以获取一个对象数组并将它们全部写入。