How can I select array of users and their related projects (many) as array?

Imagine I have these schemas:
// users table
export const users = pgTable("users", {
id: uuid("id").primaryKey().defaultRandom(),
name: text("name"),
});

// projects table
export const projects = pgTable("projects", {
id: uuid("id").primaryKey().defaultRandom(),
userId: uuid("user_id").references(() => users.id),
title: text("title"),
});
// users table
export const users = pgTable("users", {
id: uuid("id").primaryKey().defaultRandom(),
name: text("name"),
});

// projects table
export const projects = pgTable("projects", {
id: uuid("id").primaryKey().defaultRandom(),
userId: uuid("user_id").references(() => users.id),
title: text("title"),
});
How can I select all users, and their related projects?
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?