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')

Open
#3,379 0 comments 4 reactions 1 assignee Claimed by @RomanNabukhotnyi View on GitHub
bug drizzle/studio rqb
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.
![image](https://github.com/drizzle-team/drizzle-orm/assets/9679076/66390e76-4a79-460f-a286-b995a2902f9e)

When I run it in the studio I get this error:
![image](https://github.com/drizzle-team/drizzle-orm/assets/9679076/722fc34e-4abb-4c5c-a3c9-4db5fdcdd046)

```
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.