dresende / node-orm2

Object Relational Mapping
http://github.com/dresende/node-orm2
MIT License
3.07k stars 376 forks source link

inserting data in parallel using async #625

Open ysagon opened 9 years ago

ysagon commented 9 years ago

I'm trying to insert data from an array in a table using async.each. It seems that the data are not inserted correctly. By using async.eachSeries it's working. It this normal?

I my (simplified) schema, I have two tables:

in nodes I have some fields and one vendor_id.

I'm doing something like that.

async.each(nodes, function(row, cb)
var extra = {vendor: row.vendor};
var node = {bla: row.bla};
nodeModel.create(node, function(err, items){
   db.models.vendor.find({name: extra.vendor}).first(function(err, myVendor){
     items.setVendor(myVendor, function(err){cb()});
   });
});

By doing this, the vendor field is only set for the latest row inserted.