'use strict';

module.exports = (sequelize, DataTypes) => {
    const GoodsFavourites = sequelize.define('GoodsFavourites', {
        id: {
            allowNull: false,
            autoIncrement: true,
            primaryKey: true,
            type: DataTypes.INTEGER
        },
        userId: {
            allowNull: false,
            type: DataTypes.INTEGER,
            onDelete: "CASCADE",
            references: {
                model: 'Users',
                key: 'id'
            }
        },
        goodsId: {
            allowNull: false,
            type: DataTypes.INTEGER,
            onDelete: "CASCADE",
            references: {
                model: "GoodsAttributes",
                key: 'id'
            }
        }
    });

    GoodsFavourites.associate = function (models) {
        GoodsFavourites.belongsTo(models.Users, {foreignKey: 'userId', sourceKey: 'id'});
        GoodsFavourites.belongsTo(models.GoodsAttributes, {foreignKey: 'goodsId', sourceKey: 'id'});
    };

    return GoodsFavourites;
};
