Created
July 29, 2020 02:24
-
-
Save derduskenga/32e28c6aced3a122ef1061f9a395264c 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
'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