sequelize.js - How to insert from select in sequelize -
we use sequelize on node js have resourse file. file has attribute userid. need: copy same files (by filesid) user. if use sql need do:
insert files (name, link, userid) select name, link, 5 files id in (1,2,3,4,10)
but how on sequelize not have ideas... custom sql query.
try this:
file.findall({ where: {id: {$in: [1,2,3,4,10]}} }).then(function(filesseq)){ //make file objects userid=5 var files = filesseq.map(function(fileseq){ var file = fileseq.tojson(); file['userid'] = 5; return file; }); return file.bulkcreate(files) }).then(function(files){ //do created files });
Comments
Post a Comment