title: How to associate objects in Sequelize (Node js)?
body: <p>I have User and File models in Sequlize. User can have several files.
  I have association 
  db.User.hasMany(db.File, {as: 'Files', foreignKey: 'userId', constraints: false});</p>
  
  <p>I want to init User object with several Files and save it to database. </p>
  
  <p>I wrote next code:</p>
  
  <pre><code> var files = [];
  
          var file1 = models.File.build();
          file1.name = "JPEG";
  
          file1.save().then(function () {
  
          });
  
          files.push(file1);
  
          var file2 = models.File.build();
          file2.name = "PNG";
  
          file2.save().then(function () {
  
          });
  
          files.push(file2);
  
  
   var newUser = models.User.build();
         newUser.email = email;
   newUser.save().then(function (usr) {
  
   files.forEach(function (item) {
       newUser.addFile(item);
  });
  
  });
  </code></pre>
  
  <p>But I found a bug, sometimes several files were not associated with the user.</p>
  
  <p>I found(in nodejs logs) commands(update) for setting foreign keys for these files. 
  But commands were not executed. Foreign keys(userId) of several files were empty.</p>
  
  <p>I think the problem is in asynchronous queries.
  How to organize code structure to avoid this bug?</p>