Filter relationship by value in parent

I have a query where I'm trying to filter related objects by a value that will be found in the root of the query. example
const response = await prisma.myObject.findMany({
where: {
myKey: true
},
select: {
someId: true, // I want to filter 'someRelatedModel' where someRelatedModel.someId == this
someRelatedModel: {
where: {
someId: // Only give me 'someRelatedModels' wher this is the same as the someId above
}
}
}
const response = await prisma.myObject.findMany({
where: {
myKey: true
},
select: {
someId: true, // I want to filter 'someRelatedModel' where someRelatedModel.someId == this
someRelatedModel: {
where: {
someId: // Only give me 'someRelatedModels' wher this is the same as the someId above
}
}
}
2 Replies
Yetzederixx
Yetzederixx2mo ago
try someId: someValue?
loobydooby
loobydoobyOP2mo ago
I don't have the list of someId at this point. I can query to get the list of all of those, then do another query to get the related models, but I was just hoping I could somehow filter that someRelatedModel in this query. I guess I could just write the raw SQL to do it if the SDK doesn't support it. I was hoping there would be a solution like:
...
someRelatedModel: {
where: { someId: '$.someId' }
}
...
...
someRelatedModel: {
where: { someId: '$.someId' }
}
...
I want to be able to do this through the SDK if possible.
SELECT t.someId, o.otherColumn
FROM MyTable t
INNER JOIN MyOtherTable o ON t.someId = o.someId
WHERE t.myKey = true;
SELECT t.someId, o.otherColumn
FROM MyTable t
INNER JOIN MyOtherTable o ON t.someId = o.someId
WHERE t.myKey = true;
My brain broke. I just added a relationship between the 2 and it fixed it
Want results from more Discord servers?
Add your server