2025-03-12 23:35:53 +00:00

82 lines
1.5 KiB
JavaScript

const config = require('../../config');
const providers = config.providers;
const crypto = require('crypto');
const bcrypt = require('bcrypt');
const moment = require('moment');
module.exports = function (sequelize, DataTypes) {
const posts = sequelize.define(
'posts',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
title: {
type: DataTypes.TEXT,
},
content: {
type: DataTypes.TEXT,
},
published_at: {
type: DataTypes.DATE,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
posts.associate = (db) => {
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
//end loop
db.posts.belongsTo(db.users, {
as: 'creator',
foreignKey: {
name: 'creatorId',
},
constraints: false,
});
db.posts.belongsTo(db.universes, {
as: 'universe',
foreignKey: {
name: 'universeId',
},
constraints: false,
});
db.posts.belongsTo(db.universes, {
as: 'universes',
foreignKey: {
name: 'universesId',
},
constraints: false,
});
db.posts.belongsTo(db.users, {
as: 'createdBy',
});
db.posts.belongsTo(db.users, {
as: 'updatedBy',
});
};
return posts;
};