I was hoping someone could help me solve why ```pr...
# orm-help
j
I was hoping someone could help me solve why
Copy code
prisma.customer.findFirst({ where: { id: 11 }, include: { visits: { where: { status: "completed" } } } })
returns customers with visits where status can be any string or even null?
h
Try this
Copy code
prisma.customer.findFirst({ where: { id: 11, visits: { status: "completed" } }, include: { visits: true } })
or don’t include visits if you don’t need it
j
I need to loop over visits (its a relation), but it only 10-20% are gonna have status: "completed" so its a waste of bandwidth and cpu usage to loop over that client-side
It errored and told me I should put 'some' in the where but that still results in everything being returned :/
h
What data are you wanting to return from the original query?
j
A customer no matter if they have visits or not, but if they do have visits I want to only return ones where status = "completed"
h
I’d have expected your first example to work then 😕
maybe try this
Copy code
prisma.customer.findFirst({ where: { id: 11 }, include: { visits: { where: { status: {equals: "completed" }} } } })
j
It doesn't seem to work, but at this point it has to be something else 😕 Its 4 AM so i better get some sleep. Thx tho
h
all good, 12.20pm in Sydney - maybe fresh eyes in the morning will help. good luck
r
@Jonas Rothmann 👋 This will work:
Copy code
prisma.customer.findFirst({ 
  where: { 
    id: 11,
    visits: { some: { status: 'completed' } },
  },
  include: { 
    visits: {  
      where: { status: "completed" } 
    } 
  } 
})
j
Ok turns out... It's all nexus-prisma that's to blame. I was naive and didn't isolate the prisma problem but as soon as I did all the code worked. I just don't understand why nexus shows all visits because I debugged it and the customer that is passed correctly only has visits with status = "completed"
It acts the exact same whether I return the customer object from prisma or { id: 11 }. Is it caching perhaps?