node.js - Unable to create child instance for one-to-many on Sequelize.js -


i creating parent , child instance using sequlize, throws following error.

site.hasmany(group,{as:'groups'}); group.belongsto(site);  //not working site.create(sitedata).then((site)=>{   site.addgroups(groupdata).then(()=>{  //also tried addgroup     next();   }); });  //this works site.create(sitedata).then((site)=>{  groupdata.siteid=site.id;  group.create(groupdata).then(()=>{     next();  }); }); 

error:

unhandled rejection typeerror: val.replace not function @ object.sqlstring.escape (c:\api\node_modules\sequelize\lib\sql-string.js:61:15) @ object.querygenerator.escape (c:\api\node_modules\sequelize\lib\dialects\abstract\query-generator.js:983:22)

suppose have task , different schedule can try and can create bulk of schedule or single task change bulkecreate create

    var ts=req.body.task_time;       tasks.create(req.body).then(function (taskvalues) {           //for adding taskid each object prepare object bulk           for(var i=0;i<ts.length;i++)           ts[i].taskid = taskvalues.id;          taskschedule.bulkcreate(ts,{ individualhooks: true }).then(function (allschedule) {              res.status(200).json({"message":"post saved successfully"});          }).catch(function (err) {             res.status(500).json(err)         }).catch(function (err) {             res.status(500).json(err);          })      }) 

your json taskschedule , whatever value set task in post body

 "task_time": [   {     "shift": "m",     "date": "01/23/2017",     "start_time": "2017-01-22 19:00:00",     "end_time": "2017-01-23 19:00:00",       "status":"2",       "user_id":"12"   },    {     "shift": "m",     "date": "01/23/2017",     "start_time": "2017-01-22 19:00:00",     "end_time": "2017-01-23 19:00:00",       "status":"2",       "user_id":"12"   }  ], 

Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -