• Model.update
    • Model.destroy

    Since you are working with multiple models, the callbacks will not return DAO instances. BulkCreate will return an array of model instances/DAOs, they will however, unlike create, not have the resulting values of autoIncrement attributes.update and destroy will return the number of affected rows.

    First lets look at bulkCreate

    1. User.bulkCreate([
    2. { username: 'barfooz', isAdmin: true },
    3. { username: 'foo', isAdmin: true },
    4. { username: 'bar', isAdmin: false }
    5. ], { returning: true }) // will return all columns for each row inserted
    6. .then((result) => {
    7. console.log(result);

    Insert several rows and return specific columns (Postgres only):

    To update several rows at once:

    1. Task.bulkCreate([
    2. {subject: 'reading', status: 'executing'},
    3. {subject: 'programming', status: 'finished'}
    4. ]).then(() => {
    5. return Task.update(
    6. { status: 'inactive' }, /* set attributes' value */
    7. { where: { subject: 'programming' }} /* where criteria */
    8. );
    9. }).then(([affectedCount, affectedRows]) => {
    10. // affectedCount will be 2
    11. }).then(tasks => {
    12. console.log(tasks) // the 'programming' tasks will both have a status of 'inactive'
    13. })

    If you are accepting values directly from the user, it might be beneficial to limit the columns that you want to actually insert.bulkCreate()accepts an options object as the second parameter. The object can have a fields parameter, (an array) to let it know which fields you want to build explicitly

    1. User.bulkCreate([
    2. { username: 'foo' },
    3. { username: 'bar', admin: true}
    4. ], { fields: ['username'] }).then(() => {
    5. })

    bulkCreate was originally made to be a mainstream/fast way of inserting records, however, sometimes you want the luxury of being able to insert multiple rows at once without sacrificing model validations even when you explicitly tell Sequelize which columns to sift through. You can do by adding a validate: true property to the options object.