-
-
Save sdepold/4697057 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') | |
, sequelize = new Sequelize('sequelize_test', 'root') | |
var Manufacturer = sequelize.define('manufacturer', { | |
name: Sequelize.STRING | |
}); | |
var GraphicsCard = sequelize.define("graphics_card", { | |
model: Sequelize.STRING, | |
RAM: Sequelize.INTEGER | |
}); | |
GraphicsCard.belongsTo(Manufacturer); | |
Manufacturer.hasMany(GraphicsCard); | |
sequelize.sync({ force: true }).success(function() { | |
new Sequelize.Utils.QueryChainer([ | |
Manufacturer.create({name:'AMD'}), | |
GraphicsCard.create({model:'650m', RAM:2}) | |
]).run().success(function(results) { | |
var amd = results[0] | |
, gc650 = results[1] | |
gc650.setManufacturer(amd).success(function() { | |
amd.getGraphicsCards().success(function(cards) { | |
console.log(cards.map(function(c) { return c.values })) | |
process.exit() | |
}) | |
}) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment