Hey everyone. I'm currently wondering if its poss...
# orm-help
l
Hey everyone. I'm currently wondering if its possible to get data from more than one table in a single query? We have a teamMember table, and a user table. We want to fetch information on each user in the teamMember table, and get the corresponding data from the user table. Is this possible to do in one query? Or would I have to use two findMany queries?
Copy code
const members = await prisma.teamMember.findMany({
where: {
      teamId,
    },
  });

  const membersInfo = [];

  members.map(async (e) => {
    const response = await prisma.user.findFirst({
      where: {
        id: e.userId,
      },
    });
    if(response) membersInfo.push(response);
  });
✅ 1
j
Yes you can query relationships, that's super basic
aka nested reads
n
Hey Logan 👋 As Jacob mentioned you could use include to define which relations should be loaded. If you can share your schema file or share teamMember and user model, I could write a sample query based on your models.