app2-api/modules/blog/post.model.js

43 lines
1.2 KiB
JavaScript
Raw Normal View History

2019-04-15 15:58:58 +00:00
'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'
});
2019-05-23 09:40:50 +00:00
Post.Comments = Post.hasMany(models.Comment, { foreignKey: 'postId' });
2019-04-15 15:58:58 +00:00
//Post.Reactions = Post.hasMany(models.PostReaction, { foreignKey: 'postId' });
//Post.User = Post.belongsTo(models.User, { foreignKey: 'userId' });
};
return Post;
};