Help understanding relations

Hey all, just trying to get my head around relations.
In this example we have a one-to-many relationship:

export const users = mysqlTable("users", {
  id: serial("id").primaryKey(),
  username: varchar("username", { length: 120 }),
});

export const blocks = mysqlTable("blocks", {
  id: serial("id").primaryKey(),
  block_type: int("type"),
  user_id: int("user_id"),
});

export const usersRelations = relations(users, ({ many }) => ({
  pagebuilder: many(blocks),
}));

(async () => {
  const user = await db.query.users.findFirst({
    where: eq(users.username, "johnsmith"),
    with: {
      pagebuilder: true,
    },
  });
  // user.pagebuilder[0].block_type ☑️
})();


How is the query 'joining' the tables when I havent defined which columns are related. Or in this case do 'all' block rows get attached?
Was this page helpful?