Drizzle TeamDT
Drizzle Teamโ€ข2y agoโ€ข
3 replies
kal

Infer typescript type from table with relations

I have a pg table with a one to many relationship. I would like to get the typescript type of this table including the one to many relation.

I've attached images of my schema files. Currently, I have come up with a solution which seems to work but seems a 'bit scuffed' as I can see it being prone to needing ammendment if I change relations in the future.

This is the type I have currently come up with.
type pgGameSummary = InferSelectModel<typeof games> & {
  moves: InferSelectModel<typeof moves>[];
};

Is there some other 'infer......` type that I can use that will achieve what I need?
image.png
image.png
Was this page helpful?