Last active
August 29, 2015 14:02
-
-
Save mrotaru/0155e3b3cbb49ba4774f 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','password'); | |
var chainer = new Sequelize.Utils.QueryChainer | |
// define models | |
var User = sequelize.define('User', {name: Sequelize.STRING}) | |
// build instances | |
var joe = User.build({name: 'Joe'}); | |
var jane = User.build({name: 'Jane'}); | |
// associations | |
// User.hasMany(User, {as: 'Children'}); // will NOT create a junction table | |
User.hasMany(User, {as: 'Children', through: 'Children'}); // will create a `Children` junction table | |
sequelize.sync().success(function(){ | |
chainer | |
.add(joe.save()) | |
.add(jane.save()) | |
.add(joe.setChildren([jane])) | |
.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