Kevin
Kevin

Reputation: 81

Sequelize: set new uuid

How do I set a new uuid to a model every time it's called?

ex:

User.find({where: true})
    .then(function(user) {
        user.changingUUID = new UUID
        return user.save();
    });

Upvotes: 0

Views: 10002

Answers (1)

Kevin
Kevin

Reputation: 81

For those who might need it:

var sequelize = require('sequelize');
User.find({where: true})
.then(function(user) {
    user.changingUUID = sequelize.Utils.generateUUID()
    return user.save();
});

For those who are interested in seeing how it's implemented in sequelize: https://github.com/sequelize/sequelize/blob/18cb700291fe519f2c77dd91d1e3504acae4b233/lib/utils.js#L652

Seeing this, I decided to use node-uuid instead.

Upvotes: 5

Related Questions