{"size": 1664, "ext": "js", "max_stars_repo_path": "src/models/Review.js", "max_stars_repo_name": "choshin314/cookbook-backend", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/models/Review.js", "max_issues_repo_name": "choshin314/cookbook-backend", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/models/Review.js", "max_forks_repo_name": "choshin314/cookbook-backend", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 24.4705882353, "max_line_length": 48, "alphanum_fraction": 0.4068509615}
module.exports = function(sequelize, DataTypes){
    const Review = sequelize.define('review', {
        rating: {
            type: DataTypes.SMALLINT,
            allowNull: false,
            validate: {
                notNull: true,
                max: 5
            }
        },
        headline: {
            type: DataTypes.STRING(50),
            allowNull: true,
            validate: {
                len: [0, 50]
            }
        },
        reviewImg: {
            type: DataTypes.TEXT,
            allowNull: true
        },
        content: {
            type: DataTypes.TEXT,
            allowNull: true
        }
    }, 
    { 
        tableName: 'reviews',
        timestamps: true,
        underscored: true 
    });

    Review.associate = function(models) {
        Review.belongsTo(models.Recipe, {
            foreignKey: {
                name: 'recipeId',
                field: 'recipe_id',
                type: DataTypes.INTEGER,
                allowNull: false,
                validate: {
                    notNull: true
                }
            },
            onDelete: 'CASCADE'
        });
        
        Review.belongsTo(models.User, {
            foreignKey: {
                name: 'userId',
                field: 'user_id',
                type: DataTypes.UUID,
                allowNull: false
            },
            as: 'user',
            onDelete: 'CASCADE'
        });

        Review.hasOne(models.Notification, {
            foreignKey: {
                name: 'newReviewId',
                field: 'new_review_id'
            }, 
            as: 'newReview'
        })
    }

    return Review;
}