drizzle-team / drizzle-team/drizzle-orm
query with `with` command doesn't work in studio but it works when running code locally - Cannot read properties of undefined (reading 'referencedTable')
- Dominant language
- TypeScript
- Stars
- 35.8k
- Forks
- 1.6k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 4
Description
My schema is like this:
```
export const users = pgTable("users", {
id: serial("id").primaryKey(),
clerkId: text("clerk_id"),
workspaceId: integer("workspace_id").references(() => workspaces.id),
});
export const usersRelations = relations(users, ({ one }) => ({
workspace: one(workspaces, {
fields: [users.workspaceId],
references: [workspaces.id],
}),
}));
export const workspaces = pgTable("workspaces", {
id: serial("id").primaryKey(),
settings: jsonb("settings")
.$type<{ crm: { tags: string[] } }>()
.default({ crm: { tags: [""] } }),
});
export const workspaceRelations = relations(workspaces, ({ many }) => ({
users: many(users),
crm: many(crm),
}));
```
I have a query like this:
```
db.query.users.findMany({
with: {
workspace: true,
},
});
```
When I run the same query in my NextJS app, it returns data.

When I run it in the studio I get this error:

```
index.js:21 TypeError: Cannot read properties of undefined (reading 'referencedTable')
at TTr (index.js:785:145026)
at Ze.buildRelationalQueryWithoutPK (session-6c35a506.js:7:7588)
at QueryPromise._getQuery (session-6c35a506.js:7:19057)
at QueryPromise._toSQL (session-6c35a506.js:7:19333)
at session-6c35a506.js:7:18824
at Object.startActiveSpan (index.js:785:147031)
at QueryPromise._prepare (session-6c35a506.js:7:18747)
at session-6c35a506.js:7:19511
at Object.startActiveSpan (index.js:785:147031)
at QueryPromise.execute (session-6c35a506.js:7:19466)
at QueryPromise.then (index.js:785:155061)
```
Contributor guide
Assessment
This issue has not been assessed yet.