title: Sequelize create object with association not working
body: <p>I am trying to create a record (Location) with an association (Weather) (insert with foreign key) and every which way I try I end up with a NULL value in the foreign key field <strong>weatherId</strong>.</p>
  
  <p>I have seen examples in the help with creating both the primary and secondary entities at the same time, but in this case I have preloaded the Weather table and the user is limited to selecting an item from a select list.</p>
  
  <p>I have found similar issues but none have answered the problem.</p>
  
  <p><strong><em>Sequelize [Node: 4.2.2, CLI: 2.2.1, ORM: 2.0.0-rc1, mysql: ^2.10.0]</em></strong></p>
  
  <p>My models are: -</p>
  
  <h1>Location</h1>
  
  <pre><code>'use strict';
  module.exports = function(sequelize, DataTypes) {
      var Location = sequelize.define('Location', {
          id: DataTypes.INTEGER,
          locationName: DataTypes.STRING
      }, {
          classMethods: {
              associate: function(models) {
                  Location.hasMany(models.Rig);
                  Location.belongsTo(models.Weather);
              }
          },
          freezeTableName: true,
          tableName: 'Location',
          timestamps: true
      });
      return Location;
  };
  </code></pre>
  
  <h1>MySQL describe for Location</h1>
  
  <pre><code>mysql&gt; desc Location;
  +--------------+--------------+------+-----+---------+----------------+
  | Field        | Type         | Null | Key | Default | Extra          |
  +--------------+--------------+------+-----+---------+----------------+
  | id           | int(11)      | NO   | PRI | NULL    | auto_increment |
  | locationName | varchar(255) | YES  |     | NULL    |                |
  | weatherId    | int(11)      | YES  |     | NULL    |                |
  | createdAt    | datetime     | NO   |     | NULL    |                |
  | updatedAt    | datetime     | NO   |     | NULL    |                |
  +--------------+--------------+------+-----+---------+----------------+
  </code></pre>
  
  <h1>Weather model</h1>
  
  <pre><code>'use strict';
  module.exports = function(sequelize, DataTypes) {
      var Weather = sequelize.define('Weather', {
          id: DataTypes.INTEGER,
          weatherDescription: DataTypes.STRING
      }, {
          classMethods: {
              associate: function(models) {
                  Weather.hasMany(models.Location);
              }
          },
          freezeTableName: true,
          tableName: 'Weather',
          timestamps: true
      });
      return Weather;
  };    
  </code></pre>
  
  <h1>MySQL describe for Weather</h1>
  
  <pre><code>mysql&gt; desc Weather;
  +--------------------+--------------+------+-----+---------+----------------+
  | Field              | Type         | Null | Key | Default | Extra          |
  +--------------------+--------------+------+-----+---------+----------------+
  | id                 | int(11)      | NO   | PRI | NULL    | auto_increment |
  | weatherDescription | varchar(255) | YES  |     | NULL    |                |
  | createdAt          | datetime     | NO   |     | NULL    |                |
  | updatedAt          | datetime     | NO   |     | NULL    |                |
  +--------------------+--------------+------+-----+---------+----------------+
  </code></pre>
  
  <p>First attempt which fails with <strong>NULL</strong> <strong>weatherId</strong></p>
  
  <pre><code>models.Location.create({
      locationName: locationName,
      weatherId: weatherId
  
  }).then(function(location) {
      res.redirect('/location');
  
  }).catch(function(reason) {
      console.log(reason);
  });
  </code></pre>
  
  <p>Second attempt which fails with <strong>NULL</strong> <strong>weatherId</strong></p>
  
  <pre><code>models.Location.create({
      locationName: locationName
  
  }).then(function(location) {
      models.Weather.find({where: { id: weatherId } }).then(function(weather) {
          location.setWeather([weather]).then(function(location) {
  
              res.redirect('/location');
  
          }).catch(function(reason) {
              console.log(reason);
          });
  
      }).catch(function(reason) {
          console.log(reason);
      });
  
  }).catch(function(reason) {
      console.log(reason);
  });
  </code></pre>
  
  <p>Yet when I do an update this works: -</p>
  
  <pre><code>models.Location.find({
      where: {
          id: locationId
      }
  }).then(function(location) {
      if (location) {
          location.setWeather([weatherId]).then(function(location) {
              location.updateAttributes({
                  locationName: locationName
              }).success(function() {
                  res.redirect('/location');
              });
          });
      }
  }).catch(function(reason) {
      console.log(reason);
      res.send(reason);
  })
  </code></pre>
  
  <p>There are no errors in the logs, but still <strong>weatherId</strong> is <strong>NULL</strong>.</p>
  
  <p>The SQL in the log does not include the <strong>weatherId</strong> as per: -</p>
  
  <pre><code>INSERT INTO `Location` (`id`,`locationName`,`createdAt`,`updatedAt`) VALUES (NULL,'test me','2016-01-04 02:33:04','2016-01-04 02:33:04');
  </code></pre>
  
  <p>Can anyone help me with this, have spent so much time on this..</p>
  
  <p>Peter</p>