Postgres 'with' returns null with basic setup?
Hi all. Trying to get my head around Drizzle's query API but I've hit a stumbling block. I've got a basic team (has many) users schema, and have created a route that gets the user's current team. This is done with the following code:
However, on logging out the result, the team field in the response object is null.
Here is my schema.ts:
What might I be doing wrong here? Been stuck on this for a while.
2 Replies
Classic user error. Issue was:
export const usersRelations = relations(users, ({ one }) => ({
team: one(teams, {
fields: [users.id],
references: [teams.id],
}),
}));
should be
export const usersRelations = relations(users, ({ one }) => ({
team: one(teams, {
fields: [users.teamId],
references: [teams.id],
}),
}));
I need to sleep 😄
It didn't throw a type error? This might be a good improvement