43 lines
1.2 KiB
JavaScript
43 lines
1.2 KiB
JavaScript
|
|
'use strict';
|
||
|
|
|
||
|
|
module.exports = function (sequelize, DataTypes) {
|
||
|
|
const Post = sequelize.define('Post', {
|
||
|
|
id: {
|
||
|
|
type: DataTypes.UUID,
|
||
|
|
defaultValue: DataTypes.UUIDV4,
|
||
|
|
primaryKey: true,
|
||
|
|
},
|
||
|
|
date: {
|
||
|
|
type: DataTypes.DATE,
|
||
|
|
allowNull: false,
|
||
|
|
defaultValue: DataTypes.NOW
|
||
|
|
},
|
||
|
|
image: {
|
||
|
|
type: DataTypes.STRING,
|
||
|
|
defaultValue: ""
|
||
|
|
},
|
||
|
|
title: {
|
||
|
|
type: DataTypes.STRING,
|
||
|
|
allowNull: false
|
||
|
|
},
|
||
|
|
content: {
|
||
|
|
type: DataTypes.TEXT,
|
||
|
|
allowNull: false
|
||
|
|
},
|
||
|
|
}, {
|
||
|
|
tableName: 'post',
|
||
|
|
freezeTableName: true,
|
||
|
|
timestamps: true,
|
||
|
|
});
|
||
|
|
|
||
|
|
Post.associate = function (models) {
|
||
|
|
Post.Categories = Post.belongsToMany(models.Category, {
|
||
|
|
through: models.PostCategory,
|
||
|
|
foreignKey: 'postId'
|
||
|
|
});
|
||
|
|
//Post.Comments = Post.hasMany(models.PostComment, { foreignKey: 'postId' });
|
||
|
|
//Post.Reactions = Post.hasMany(models.PostReaction, { foreignKey: 'postId' });
|
||
|
|
//Post.User = Post.belongsTo(models.User, { foreignKey: 'userId' });
|
||
|
|
};
|
||
|
|
return Post;
|
||
|
|
};
|