Last active
March 31, 2016 05:40
-
-
Save maxkoryukov/71ca090953c788b34b67243170226ee6 to your computer and use it in GitHub Desktop.
Revisions
-
maxkoryukov revised this gist
Mar 31, 2016 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -66,6 +66,7 @@ p.update({ .then(x => { // TODO : define type of promise arg }) ``` ### Without any instances -
maxkoryukov revised this gist
Mar 31, 2016 . 1 changed file with 29 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -50,4 +50,32 @@ builder.findById(bid, { // -> returns `promise` around delete counter }); ``` ## Update ### Using persisted instance ```js // let p = person.findById ... - assume, you already have found the instance p.update({ surname: 'new value' }) .then(x => { // TODO : define type of promise arg }) ### Without any instances ```js person.update( { note: 'new value' }, { fields: ['note'], where: {id: id} } ).then( x => { }); // TODO : type of x , don't know what it is... ``` -
maxkoryukov revised this gist
Mar 30, 2016 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -3,8 +3,7 @@ <a id="many-to-many"> ## Many to many ```js var person = sequelize.define("person", { id: { type: DataTypes.INTEGER, -
maxkoryukov renamed this gist
Mar 30, 2016 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
maxkoryukov created this gist
Mar 30, 2016 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,54 @@ # Sequelize Cheat Sheet <a id="many-to-many"> ## 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 }); ```