Skip to content

Instantly share code, notes, and snippets.

@sdepold
Forked from mlaccetti/hasmany-belongsto.js
Last active December 12, 2015 02:18
Show Gist options
  • Save sdepold/4697057 to your computer and use it in GitHub Desktop.
Save sdepold/4697057 to your computer and use it in GitHub Desktop.
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