I am trying to save a json object that is sent by a client, in the database
The application can handle requests just fine, but i am stuck when it comes to saving the request data in the database, i am using sequelize.
Here are my models:
Schedule Model
module.exports = (sequelize, DataTypes) => {
const Schedules = sequelize.define('Schedules', {
name: DataTypes.STRING,
delay: DataTypes.INTEGER,
criteria: DataTypes.STRING
}, {})
Schedules.associate = (models) => {
Schedules.hasMany(models.Commands)
}
return Schedules
}
and the commands model
module.exports = (sequelize, DataTypes) => {
const Commands = sequelize.define('Commands', {
command: DataTypes.STRING,
index: DataTypes.INTEGER
},{})
Commands.associate = (models) => {
Commands.belongsTo(models.Schedules)
}
return Commands
}
Finally here is the request json object that is recieved
{
"name": "Do Something",
"commands": [
"step one",
"step two",
"step three"
]
}
Also i need to make sure when a schedule is queried, it shall return the commands[] array in that order. My Question is, How can i do so in sequelize, Any help is appreciated. Thanks