Skip to content

Instantly share code, notes, and snippets.

@mrotaru
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrotaru/bea0a299139e1e2f92ee to your computer and use it in GitHub Desktop.
Save mrotaru/bea0a299139e1e2f92ee to your computer and use it in GitHub Desktop.
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