Folks, in Prisma v2 how I use query if a type has ...
# orm-help
a
Folks, in Prisma v2 how I use query if a type has entries? I’m not getting with this query:
Copy code
prisma.category.findMany({
  where: {
    basket: {
      where: {
        food: {
          where: {
            id: true
          }
        }
      }
    }
  }
})
m
Copy code
prisma.category.findMany({
  where: {
    basket: {
      where: {
        food: {
          where: {
            id: { not: null }
          }
        }
      }
    }
  }
})
is that what you meant?
a
Don’t work, this
food
it’s actually is plural, or array
I’ve been trying for hours 😪
I am trying to return the category if a type (in depth) has content.
m
have you tried something like
Copy code
prisma.food.findMany({ where: <filter for food> } }).basket().category()
a
I get error
Expected at most 1 item for 'category', got 6
j
Does this work @Adriano Resende?
Copy code
prisma.category.findMany({
  where: {
    basket: {
      where: {
        food: {
          where: {
            some: {
              id: { not: null }
            }
          }
        }
      }
    }
  }
})
https://www.prisma.io/docs/reference/tools-and-interfaces/prisma-client/crud#type-1
a
@Jack Not work =/ The best I could get was like this:
Copy code
prisma.category.findMany({
  where: {
    baskets: {
      some: {
        foods: {
          some: {
            published: true
          }
        }
      }
    }
  }
})
But return some foods empty
j
Could try
every
instead? Not 100% sure what final result you're aiming for tbh!
a
Return with empty too =/ I’ll create an issue on github