const { DataTypes, Model } = require("sequelize"); const sequelize = require("../../config/sequelize"); class Favorite extends Model { } const FavoriteModel = () => { Favorite.init( { userId: { type: DataTypes.STRING(24), allowNull: false, primaryKey: true, references: { model: 'user', key: 'id' } }, articleId: { type: DataTypes.INTEGER, allowNull: false, primaryKey: true, references: { model: 'article', key: 'id' } } }, { sequelize, tableName: 'favorite', timestamps: false, indexes: [ { name: "PRIMARY", unique: true, using: "BTREE", fields: [ { name: "userId" }, { name: "articleId" }, ] }, { name: "articleId", using: "BTREE", fields: [ { name: "articleId" }, ] }, ] } ); Favorite.prototype.toJSONFor = function () { return { userId: this.userId, articleId: this.articleId }; }; return Favorite; }; module.exports = FavoriteModel;