Marc
Marc
Explore posts from servers
DTDrizzle Team
Created by Marc on 3/7/2024 in #help
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,
},
},
},
},
},
});
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)
}
})
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
}
}
}
}
}
}
})
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 ! 😄
5 replies