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();


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 }
  }
]


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 πŸ™‚
Was this page helpful?