Sequelize.js 如何在sequelize中创建和种子关联模型?

Sequelize.js 如何在sequelize中创建和种子关联模型?,sequelize.js,Sequelize.js,我有一个Comment模型,它属于User模型。这就是我创建它的方式: var log_status = console.log; var u = require("lodash"); models.sequelize.sync({ force: true, logging: log_status, }).then(function() { return models.Users.bulkCreate([ { first_name: "John", last_name:

我有一个
Comment
模型,它
属于
User
模型。这就是我创建它的方式:

var log_status = console.log;
var u = require("lodash");

models.sequelize.sync({
  force: true,
  logging: log_status, 
}).then(function() {
  return models.Users.bulkCreate([
    { first_name: "John", last_name: "Smith" },
    { first_name: "Jane", last_name: "Carter" },
  ], {logging: log_status});
}).then(function() { 
    return models.Users.findAll({logging: log_status}); 
}).then(function(users) {
  user_ids = u.object(u.map(users, function (x){ 
    return [x.first_name + " " x.last_name, x.id];
  }));
  return models.Comment.bulkCreate([
    { UserId: user_ids["John Smith"], body: "This is a comment" },
    { UserId: user_ids["John Smith"], body: "This is another comment" },
    { UserId: user_ids["Jane Carter"], body: "This is my comment" },
  ], {logging: log_status});
}).then(function(comments) {
  comment_ids = u.object(u.map(comments, function (x){ 
    return [x.first_name + " " x.last_name, x.id];
  }));

  // ...
});
因为我使用sqlite作为我的数据库,所以我必须使用
findAll
来获取ID,因为。这是可行的,但我想知道是否有更好的方法来填充关联模型