There's a good answer here.
Simple working solution:
'use strict';
var Sequelize = require('sequelize');
var sequelize = new Sequelize(/*database*/'test', /*username*/'test', /*password*/'test',
{host: 'localhost', dialect: 'postgres'});
var User = sequelize.define('User', {
firstName: {type: Sequelize.STRING},
lastName: {type: Sequelize.STRING}
});
var Vehicle = sequelize.define('Vehicle', {
brand: {type: Sequelize.STRING}
});
var firstUser;
User.hasMany(Vehicle, {constraints: true});
Vehicle.belongsTo(User, {constraints: true});
sequelize.sync({force: true})
.then(function () {
return User.create({firstName: 'Test', lastName: 'Testerson'});
})
.then(function (author1) {
firstUser = author1;
return Vehicle.create({UserId: firstUser.id, brand: 'Ford'});
})
.then(function () {
return Vehicle.create({UserId: firstUser.id, brand: 'Toyota'})
})
.then(function () {
return User.findAll({
where: {id: 1},
include: [Vehicle]
});
})
.then(function displayResults(results) {
results.forEach(function (c) {
console.dir(c.toJSON());
});
})
.then(function () {
process.exit(0);
});