Skip to content

Instantly share code, notes, and snippets.

@Abazhenov
Last active September 21, 2017 14:47
Show Gist options
  • Save Abazhenov/1064cb816e8ba56cc186dd833af17228 to your computer and use it in GitHub Desktop.
Save Abazhenov/1064cb816e8ba56cc186dd833af17228 to your computer and use it in GitHub Desktop.
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