import { DataTypes, InferAttributes, InferCreationAttributes, Model, NonAttribute, Sequelize, } from "sequelize"; import { Quote_Model } from "./quote.model"; export type QuoteChapterCreationAttributes = InferCreationAttributes; export class QuoteChapter_Model extends Model< InferAttributes, InferCreationAttributes > { static associate(connection: Sequelize) { const { Quote_Model, QuoteChapter_Model } = connection.models; QuoteChapter_Model.belongsTo(Quote_Model, { as: "quote", foreignKey: "quote_id", onDelete: "CASCADE", }); } declare quote_id: string; declare chapter_id: string; declare position: number; declare description: string; declare quote: NonAttribute; } export default (sequelize: Sequelize) => { QuoteChapter_Model.init({ quote_id: { type: DataTypes.UUID, primaryKey: true }, chapter_id: { type: DataTypes.UUID, primaryKey: true }, position: { type: DataTypes.MEDIUMINT, allowNull: false }, description: { type: DataTypes.TEXT, allowNull: false }, }, { sequelize, tableName: "quote_chapters", timestamps: false, indexes: [{ name: "quote_chapters_position_idx", fields: ["quote_id", "position"] }], }); return QuoteChapter_Model; };