title: Sequelize dynamic seeding
body: <p>I'm currently seeding data with Sequelize.js and using hard coded values for association IDs. This is not ideal because I really should be able to do this dynamically right? For example, associating users and profiles with a "has one" and "belongs to" association. I don't necessarily want to seed users with a hard coded <code>profileId</code>. I'd rather do that in the profiles seeds after I create profiles. Adding the <code>profileId</code> to a user dynamically once profiles have been created. Is this possible and the normal convention when working with Sequelize.js? Or is it more common to just hard code association IDs when seeding with Sequelize?</p>
  
  <p>Perhaps I'm going about seeding wrong? Should I have a one-to-one number of seeds files with migrations files using Sequelize? In Rails, there is usually only 1 seeds file you have the option of breaking out into multiple files if you want.</p>
  
  <p>In general, just looking for guidance and advice here. These are my files:</p>
  
  <p>users.js</p>
  
  <pre><code>// User seeds
  
  'use strict';
  
  module.exports = {
    up: function (queryInterface, Sequelize) {
      /*
        Add altering commands here.
        Return a promise to correctly handle asynchronicity.
  
        Example:
        return queryInterface.bulkInsert('Person', [{
          name: 'John Doe',
          isBetaMember: false
        }], {});
      */
  
      var users = [];
      for (let i = 0; i &lt; 10; i++) {
        users.push({
          fname: "Foo",
          lname: "Bar",
          username: `foobar${i}`,
          email: `foobar${i}@gmail.com`,
          profileId: i + 1
        });
      }
      return queryInterface.bulkInsert('Users', users);
    },
  
    down: function (queryInterface, Sequelize) {
      /*
        Add reverting commands here.
        Return a promise to correctly handle asynchronicity.
  
        Example:
        return queryInterface.bulkDelete('Person', null, {});
      */
      return queryInterface.bulkDelete('Users', null, {});
    }
  };
  </code></pre>
  
  <p>profiles.js</p>
  
  <pre><code>// Profile seeds
  
  'use strict';
  var models = require('./../models');
  var User = models.User;
  var Profile = models.Profile;
  
  
  module.exports = {
    up: function (queryInterface, Sequelize) {
      /*
        Add altering commands here.
        Return a promise to correctly handle asynchronicity.
  
        Example:
        return queryInterface.bulkInsert('Person', [{
          name: 'John Doe',
          isBetaMember: false
        }], {});
      */
  
      var profiles = [];
      var genders = ['m', 'f'];
      for (let i = 0; i &lt; 10; i++) {
        profiles.push({
          birthday: new Date(),
          gender: genders[Math.round(Math.random())],
          occupation: 'Dev',
          description: 'Cool yo',
          userId: i + 1
        });
      }
      return queryInterface.bulkInsert('Profiles', profiles);
    },
  
    down: function (queryInterface, Sequelize) {
      /*
        Add reverting commands here.
        Return a promise to correctly handle asynchronicity.
  
        Example:
        return queryInterface.bulkDelete('Person', null, {});
      */
      return queryInterface.bulkDelete('Profiles', null, {});
    }
  };
  </code></pre>
  
  <p>As you can see I'm just using a hard coded <code>for</code> loop for both (not ideal).</p>