34383432
34383432
Explore posts from servers
DTDrizzle Team
Created by 34383432 on 3/3/2024 in #help
I need help with simple Table design 🥺
Hello! I've been trying to make a simple category-images relation work for past two days and I keep running into cannot infer relation errors. I finally have a working schema: export const categories = pgTable("categories", { id: text("id").primaryKey().unique(), parentId: text("parent_id").notNull() }); export const images = pgTable("images", { id: text("id").primaryKey().unique(), categoryId: text("category_id") .notNull().references(() => categories.id), } and relations: export const categoriesRelations = relations(categories, ({ one, many }) => ({ parent: one(categories, { relationName: "children", fields: [categories.parentId], references: [categories.id] }), children: many(categories, { relationName: "children" }), images: many(images, { relationName: "images" }), })); export const imagesRelations = relations(images, ({ one }) => ({ category: one(categories, { fields: [images.categoryId], references: [categories.id], relationName: "images" }), })); however I'm only able to query images that are directly related to categories. what I'd like to do is to be able to query category "all" and get images that are nested deep in the category three, like image with a relation to "lion" category, given that category three looks like this: "/all/nature/animals/lion". All tips are appreciated 🙏
3 replies
TTCTheo's Typesafe Cult
Created by 34383432 on 1/20/2024 in #questions
Clerk Metadata data loss if user signs in using the sign up modal
No description
1 replies