Last active
September 21, 2017 14:47
-
-
Save Abazhenov/1064cb816e8ba56cc186dd833af17228 to your computer and use it in GitHub Desktop.
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 characters
const db = require('../_db'); | |
const Sequelize = require('sequelize'); | |
class tag extends Sequelize.Model { | |
Associate(Models) { | |
for (const Model of Models) { | |
Model.belongsToMany(this, { | |
foreignKey: 'foreign_key', | |
constraints: false, | |
through: { | |
model: db.models.tag_link, | |
unique: false, | |
scope: { | |
table: Model.name | |
} | |
} | |
}) | |
this.belongsToMany(Model, { | |
foreign_key: 'tag_id', | |
through: { | |
model: db.models.tag_link, | |
unique: false, | |
} | |
}) | |
} | |
} | |
} | |
tag.init({ | |
name: { | |
type: Sequelize.STRING(100), | |
allowNull: false, | |
} | |
},{ | |
sequelize: db, | |
tableName: 'tag', | |
}); | |
module.exports = tag |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment