danba
danba

Reputation: 877

Create multiple sails models on single request

I'm uploading a CSV file to the sails app. At this point it should do two things:

  1. the UploadController should store the unaltered uploaded file using the UploadModel
  2. the UploadController should parse the file and store each entry in the EntryModel

My first thought was I could do something like

entries = parse(data);
foreach(entry in entries) {
    sails.models.entry.create(entry);
}

but this approach silently fails.

Is there a proper way to handle this sort of scenario?

Thanks!

Upvotes: 1

Views: 2599

Answers (1)

sgress454
sgress454

Reputation: 24958

You can call .create with an array of objects to create multiple models; this is referred to in the documentation for .create(). So:

sails.models.entry.create(entries).exec(...);

should work fine.

Upvotes: 6

Related Questions