How to structure posts with categories using drizzle and postgres (supabase)
I have been working on how to set up businesses, categories, and businessToCategories (join) tables and properly querying so that I can pass an array of category ids and only get back the related posts. I am trying to use the query api so that my return types are consistent.
I should be able to ask for all posts with a category id of [1,2] and it return just those posts. Currently I am able to retrieve all businesses with their businessToCategories id and then finally the nested category name and icon. How can i filter via the initial where clause referencing a relation?
I have the three tables defined in schema and pushed live:
5 Replies
My Trpc query:
Would this work?
I will test and let you know asap
@Sillvva I get error:
TRPCClientError: invalid reference to FROM-clause entry for table "create-t3-app_businessEntity
Hmm. I'm not familiar with that error. Try changing the where clause to a function. Then reference the businessEntities table from the function params.
Not sure if that will change anything in the resulting query. But I guess it's worth a shot. This is how I did it in my app.
Ah that works most of the way. I think i can figure it out from here!
THANK YOU