Β© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Teamβ€’3y agoβ€’
22 replies
divby0

Many-to-Many joins results in weird values

Hey, I am new to Prisma, switching here from prisma so I can use a typesafe orm with D1 properly. I am trying to return a many-to-many joined result:

  const teamedUser = await db.select().from(usersToTeams)
    .where(eq(usersToTeams.user, user.id))
    .innerJoin(users, eq(usersToTeams.user, users.id))
    .innerJoin(teams, eq(usersToTeams.team, teams.id))
    .all();
  const teamedUser = await db.select().from(usersToTeams)
    .where(eq(usersToTeams.user, user.id))
    .innerJoin(users, eq(usersToTeams.user, users.id))
    .innerJoin(teams, eq(usersToTeams.team, teams.id))
    .all();


This already returns a correct structure:
[
  {
    usersToTeams: { user: 4, team: 2 },
    users: {
      id: 2,
      email: '<email>',
      password: '<password-hash>',
      name: '<this field is undefined, but weirdly it puts in the users email>'
    },
    teams: { id: undefined, name: undefined }
  }
]
[
  {
    usersToTeams: { user: 4, team: 2 },
    users: {
      id: 2,
      email: '<email>',
      password: '<password-hash>',
      name: '<this field is undefined, but weirdly it puts in the users email>'
    },
    teams: { id: undefined, name: undefined }
  }
]


The weird things are:
- the name field of the user is not set (it's undefined in reality, if I use sqlite to look at the row), but my (maybe wrong) query fills it with the user's email??
- the teams object has only undefined values in it even though id as well as name are set
- I'd like to not select the password field of the user, how can I do that? I tried looking up partial selects in combination with joined fields, but nothing that I tried worked

I'd really appreciate help πŸ™‚ drizzle really looks cool, I just have to learn a few more things, I guess.

PS: if that matters, I am using the sqlite / D1 variant of drizzle πŸ™‚
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Joins with results in arrays
Drizzle TeamDTDrizzle Team / help
2y ago
How to flatten select results from query with left joins (one-to-many)?
Drizzle TeamDTDrizzle Team / help
3y ago
Many to Many to Many
Drizzle TeamDTDrizzle Team / help
12mo ago
What's the recommended way to handle joins that aggregate results?
Drizzle TeamDTDrizzle Team / help
15mo ago