title: sailsjs error handling when creating two models
body: <p>I'm pretty new two nodejs and sails. I'm trying to create two models inside one action. My question is how to handle the errors which can occur in both queries.</p>
  
  <p>Current Code:</p>
  
  <pre><code>new: function (req, res) {
      var errorArray = [];
      var data = req.allParams();
  
          User.create({
              username: data.username,
              password: data.password,
              device_id: data.device_id,
              own_number: data.own_number,
              mobile_numbers: data.mobile_numbers
          }).exec(function (err, user) {
              if(err){
              errorArray.push(err);
              }
          });
  
          Mobile_number.create({
            number: data.own_number,
            number_id: this.hash(data.own_number)
          }).exec(function(err, mobile_number){
            sails.log(err);
            if(err){
              errorArray.push(err);
            }
         });
  
         if(errorArray.length == 0){
           return res.ok('success');
         }else {
          return res.send(errorArray.toString());
         }    
    }
  </code></pre>
  
  <p>The problem with this code is that the if at the end is handled before the queries finish. What would be the right way for to wait for the queries?</p>
  
  <p>Bruno</p>