Last active
August 29, 2015 14:02
-
-
Save mrotaru/bea0a299139e1e2f92ee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Sequelize = require('sequelize'); | |
var sequelize = new Sequelize('db','db_user','db_password'); | |
var chainer = new Sequelize.Utils.QueryChainer | |
var User = sequelize.define('User', {name: Sequelize.STRING}, {timestamps: false}) | |
var City = sequelize.define('City', {name: Sequelize.STRING}, {timestamps: false}) | |
var joe = User.build({name: 'Joe'}); | |
var london = City.build({name: 'London'}); | |
User.belongsTo(City); | |
sequelize.sync().success(function(){ | |
chainer | |
/* will not work ! see https://github.com/sequelize/sequelize/issues/1954#issuecomment-46954587 | |
.add(joe.save()) | |
.add(london.save()) | |
.add(joe.setCity(london)) | |
*/ | |
.add(joe, 'save') | |
.add(london, 'save') | |
.add(joe, 'setCity', london) | |
.runSerially() | |
.success(function(){ console.log('all good');}) | |
.error(function(err){ console.log(err);}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment