Created
January 16, 2014 16:01
-
-
Save FredrikAppelros/8457460 to your computer and use it in GitHub Desktop.
sequelize hook problem
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
Sequelize = require 'sequelize' | |
sequelize = new Sequelize 'sequelize-test', 'postgres', 'changeme123', | |
host: 'localhost' | |
port: 5432 | |
dialect: 'postgres' | |
A = sequelize.define 'A', name: Sequelize.STRING | |
B = sequelize.define 'B', name: Sequelize.STRING | |
A.addHook 'afterCreate', (instance, done) -> | |
console.log 'afterCreate', JSON.stringify instance | |
done() | |
B.hasMany A | |
A.hasMany B | |
sequelize.sync().complete -> | |
chainer = new Sequelize.Utils.QueryChainer [ | |
A.create name: 'a' | |
B.create name: 'b' | |
] | |
chainer.run().success (res, a, b) -> | |
a.addB(b).success -> sequelize.drop() |
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
{ | |
"name": "sequelize-hook-problem", | |
"version": "0.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "", | |
"license": "BSD-1-Clause", | |
"dependencies": { | |
"sequelize": "~2.0.0-dev1", | |
"pg": "~2.11.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment