app2-api/modules/blog/post.model.js
2019-07-26 16:50:53 +02:00

55 lines
1.6 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.Reactions = Post.hasMany(models.PostReaction, { foreignKey: 'postId' });
//Post.User = Post.belongsTo(models.User, { foreignKey: 'userId' });
//OJO antes de force comentar
// OJO GENERA UN FOREIGN KEY Con eventos y habrá ID de otras entidades que no exitan en la tabla eventos, porque son post o speakers
Post.Multimedias = Post.hasMany(models.Multimedia, {
foreignKey: 'entityId',
as: { singular: 'multimedia', plural: 'multimedias' }
});
Post.Comments = Post.hasMany(models.Comment, {
foreignKey: 'entityId',
as: { singular: 'comment', plural: 'comments' }
});
};
return Post;
};