不要怂,就是干,撸起袖子干!

Commit 3ee9e121 by Sascha Depold

Sequelize#sync

1 parent bf37e532
......@@ -40,6 +40,21 @@ var instanceMethods = {
options = options || {}
options.logging = this.options.hasOwnProperty('logging') ? this.options.logging : true
return new Query(this.config, callee, options).run(sql)
},
sync: function(options) {
var self = this
var eventEmitter = new Utils.CustomEventEmitter(function() {
var chainer = new Utils.QueryChainer
self.modelManager.models.forEach(function(model) { chainer.add(model.sync(options)) })
chainer
.run()
.on('success', function() { eventEmitter.emit('success', null) })
.on('failure', function() { eventEmitter.emit('failure', null) })
})
return eventEmitter.run()
}
}
......
var assert = require("assert")
, config = require("./../config")
, Sequelize = require("./../../index")
, sequelize = new Sequelize(config.database, config.username, config.password, {logging: false})
module.exports = {
'it should sync all models - so instances can be created and saved to the database without failures': function(exit) {
var Project = sequelize.define('project' + parseInt(Math.random() * 9999999999999999999), {
title: Sequelize.STRING
})
var Task = sequelize.define('task' + parseInt(Math.random() * 99999999999999999), {
title: Sequelize.STRING
})
sequelize.sync().on('success', function() {
Project.create({title: 'bla'}).on('success', function() {
Task.create({title: 'bla'}).on('success', function() {
exit(function(){})
})
})
})
}
}
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!