Drizzle TeamDT
Drizzle Team•2y ago
Marc

Can I use "where" clause on joins ?

Hello !

I'm trying to query some data based on conditions. I know how to do it in prisma but I don't find a solution in drizzle.

In Prisma my query looks like:
const modelId = "dummyModelId";
const userId = "dummyUserId";

const data = await prisma.model.findFirst({
  where: {
    id: modelId,
    task: {
      dataset: {
        userDatasets: {
          some: {
            userId,
          },
        },
      },
    },
  },
});


In Drizzle I have currenlty this:
const modelId = "dummyModelId";
const userId = "dummyUserId";

const data = await db.query.model.findFirst({
  where({id}){
    return eq(id, modelId)
  }
})


I've tried this:
const data = await db.query.model.findFirst({
  where({id}){
    return eq(id, modelId)
  },
  with:{
    task:{
      with:{
        dataset:{
          with:{
            userDatasets:{
              // 'where' clause not possible here
            }
          }
        }
      }
    }
  }
})


I would like to use 'where' clause on fields that are in other tables.

Thanks for the help ! 😄
Was this page helpful?