v2.5.2
Giriş yap

Node Sequelize (Tablo ilişkilendirme)

mertnrist
88 defa görüntülendi

Product ve Category tablolarım var her ürünün birden fazla kategoriye sahip olmasını istiyorum nasıl yapabilirim? Sequelize kullanıyorum

const database = require('../database/db')
const { DataTypes } = require('sequelize')

const Category = database.define(
	'categories',
	{
		id: {
			type: DataTypes.INTEGER,
			primaryKey: true,
			autoIncrement: true,
		},
		name: {
			type: DataTypes.STRING,
			allowNull: false,
		},
	},
	{
		timestamps: true,
	}
)

module.exports = Category

const database = require('../database/db')
const { DataTypes } = require('sequelize')

const Product = database.define(
	'products',
	{
		id: {
			type: DataTypes.INTEGER,
			primaryKey: true,
			autoIncrement: true,
		},
		name: {
			type: DataTypes.STRING,
			allowNull: false,
		},
		description: {
			type: DataTypes.STRING,
			allowNull: false,
		},
		price: {
			type: DataTypes.INTEGER,
			allowNull: false,
		},
		image: {
			type: DataTypes.STRING,
			allowNull: false,
		},
	},
	{
		timestamps: true,
	}
)

module.exports = Product


Cevap yaz
Cevaplar (0)
Henüz kimse cevap yazmadı. İlk cevap yazan sen ol!