27 lines
604 B
27 lines
604 B
import { Sequelize } from "sequelize";
|
|
import db from "../config/database.js";
|
|
import blogImage from "./blogImage.js";
|
|
|
|
const { DataTypes } = Sequelize;
|
|
|
|
const Blog = db.define("blog", {
|
|
title: {
|
|
type: DataTypes.STRING,
|
|
allowNull: false,
|
|
},
|
|
description: {
|
|
type: DataTypes.TEXT,
|
|
allowNull: false,
|
|
},
|
|
slug: {
|
|
type: DataTypes.STRING,
|
|
allowNull: false,
|
|
unique: true,
|
|
},
|
|
});
|
|
|
|
// Definisi relasi dengan alias 'images'
|
|
Blog.hasMany(blogImage, { foreignKey: "blogId", as: "images" });
|
|
blogImage.belongsTo(Blog, { foreignKey: "blogId", as: "blog" });
|
|
|
|
export default Blog;
|