31132/backend/src/db/models/outfit_options.js
2025-04-30 21:13:34 +00:00

60 lines
1.3 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 outfit_options = sequelize.define(
'outfit_options',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
description: {
type: DataTypes.TEXT,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
outfit_options.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.outfit_options.hasMany(db.file, {
as: 'images',
foreignKey: 'belongsToId',
constraints: false,
scope: {
belongsTo: db.outfit_options.getTableName(),
belongsToColumn: 'images',
},
});
db.outfit_options.belongsTo(db.users, {
as: 'createdBy',
});
db.outfit_options.belongsTo(db.users, {
as: 'updatedBy',
});
};
return outfit_options;
};