## Many to many
var person = sequelize.define("person", {
id: {
type: DataTypes.INTEGER,
allowNull: false,
primaryKey: true,
autoIncrement: true
},
name: DataTypes.STRING(500),
phone: DataTypes.STRING(500),
});
var employee = sequelize.define("employee", {
id: {
type: DataTypes.INTEGER,
allowNull: false,
primaryKey: true,
autoIncrement: true
},
job: DataTypes.STRING(500),
});
var builder = sequelize.define("builder", {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true
},
name: DataTypes.STRING(100),
});
builder.belongsToMany(person, {as: 'employees', through: employee});
person.belongsToMany(builder, {as: 'employers', through: employee});
builder.findById(bid, {
include: [{
model: person,
as: 'employees',
}]
})
.then( builder => {
// UNLINK:
return b.removeEmployee(eid);
// -> returns `promise` around delete counter
});
person.update(
{ note: 'new value' },
{
fields: ['note'],
where: {id: id}
}
).then( x => {
}); // TODO : type of x , don't know what it is...