47 lines
1.3 KiB
TypeScript
47 lines
1.3 KiB
TypeScript
|
|
import {
|
||
|
|
DataTypes,
|
||
|
|
InferAttributes,
|
||
|
|
InferCreationAttributes,
|
||
|
|
Model,
|
||
|
|
NonAttribute,
|
||
|
|
Sequelize,
|
||
|
|
} from "sequelize";
|
||
|
|
import { Quote_Model } from "./quote.model";
|
||
|
|
|
||
|
|
export type QuoteChapterCreationAttributes = InferCreationAttributes<QuoteChapter_Model>;
|
||
|
|
|
||
|
|
export class QuoteChapter_Model extends Model<
|
||
|
|
InferAttributes<QuoteChapter_Model>,
|
||
|
|
InferCreationAttributes<QuoteChapter_Model>
|
||
|
|
> {
|
||
|
|
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<Quote_Model>;
|
||
|
|
}
|
||
|
|
|
||
|
|
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;
|
||
|
|
};
|