mirror of
https://gitea.gofwd.group/sean/gunbuilder-next-tailwind.git
synced 2025-12-06 02:56:45 -05:00
shit show but data works
This commit is contained in:
53
drizzle/migrations/relations.ts
Normal file
53
drizzle/migrations/relations.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { relations } from "drizzle-orm/relations";
|
||||
import { categories, productCategoryMappings, products, offers, offerPriceHistory, productAttributes } from "./schema";
|
||||
|
||||
export const productCategoryMappingsRelations = relations(productCategoryMappings, ({one}) => ({
|
||||
category: one(categories, {
|
||||
fields: [productCategoryMappings.canonicalCategoryId],
|
||||
references: [categories.id]
|
||||
}),
|
||||
}));
|
||||
|
||||
export const categoriesRelations = relations(categories, ({one, many}) => ({
|
||||
productCategoryMappings: many(productCategoryMappings),
|
||||
category: one(categories, {
|
||||
fields: [categories.parentId],
|
||||
references: [categories.id],
|
||||
relationName: "categories_parentId_categories_id"
|
||||
}),
|
||||
categories: many(categories, {
|
||||
relationName: "categories_parentId_categories_id"
|
||||
}),
|
||||
products: many(products),
|
||||
}));
|
||||
|
||||
export const productsRelations = relations(products, ({one, many}) => ({
|
||||
category: one(categories, {
|
||||
fields: [products.canonicalCategoryId],
|
||||
references: [categories.id]
|
||||
}),
|
||||
offers: many(offers),
|
||||
productAttributes: many(productAttributes),
|
||||
}));
|
||||
|
||||
export const offersRelations = relations(offers, ({one, many}) => ({
|
||||
product: one(products, {
|
||||
fields: [offers.productId],
|
||||
references: [products.id]
|
||||
}),
|
||||
offerPriceHistories: many(offerPriceHistory),
|
||||
}));
|
||||
|
||||
export const offerPriceHistoryRelations = relations(offerPriceHistory, ({one}) => ({
|
||||
offer: one(offers, {
|
||||
fields: [offerPriceHistory.offerId],
|
||||
references: [offers.id]
|
||||
}),
|
||||
}));
|
||||
|
||||
export const productAttributesRelations = relations(productAttributes, ({one}) => ({
|
||||
product: one(products, {
|
||||
fields: [productAttributes.productId],
|
||||
references: [products.id]
|
||||
}),
|
||||
}));
|
||||
Reference in New Issue
Block a user