Skip to content

Instantly share code, notes, and snippets.

@derduskenga
Created Jul 29, 2020
Embed
What would you like to do?
'use strict';
const {
Model
} = require('sequelize');
module.exports = (sequelize, DataTypes) => {
class Tag extends Model {
/**
* Helper method for defining associations.
* This method is not a part of Sequelize lifecycle.
* The `models/index` file will call this method automatically.
*/
static associate(models) {
// define association here
Tag.belongsToMany(models.Post,{
through: models.PostTag,
foreignKey:'tag_id'
})
}
};
Tag.init({
tag_text: DataTypes.STRING
}, {
sequelize,
modelName: 'Tag',
});
return Tag;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment