Skip to content

Instantly share code, notes, and snippets.

@derduskenga
Created July 29, 2020 02:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save derduskenga/32e28c6aced3a122ef1061f9a395264c to your computer and use it in GitHub Desktop.
Save derduskenga/32e28c6aced3a122ef1061f9a395264c to your computer and use it in GitHub Desktop.
'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