Sequelize:设置新的uuid

时间:2015-04-19 03:12:43

标签: node.js sequelize.js

如何在每次调用时为模型设置一个新的uuid?

例如:

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

1 个答案:

答案 0 :(得分:5)

对于那些可能需要它的人:

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

对于那些有兴趣了解它如何在续集中实施的人: https://github.com/sequelize/sequelize/blob/18cb700291fe519f2c77dd91d1e3504acae4b233/lib/utils.js#L652

看到这一点,我决定改用node-uuid