How can I make a query with prisma as follows Jus...
# orm-help
y
How can I make a query with prisma as follows Just give me the categories that have subcategories. So I want it to list the categories that do not contain subcategories.
r
If you're looking for categories without subcategories then try:
Copy code
prisma.category.findMany({ 
  where: {
     subcategory: {
       none: {}
    }
  }
});
y
Thanks @Richard Ward I am looking for categories only have sub categories?
n
Hey @Yiğit Rüzgar 👋 I think in that case you can use `some`:
Copy code
const categories = await prisma.category.findMany({
  where: {
    subCategories: {
      some: {},
    },
  },
})
With this data:
Copy code
┌─────────┬────┬───────────┬──────────────────┐
│ (index) │ id │   name    │ parentCategoryId │
├─────────┼────┼───────────┼──────────────────┤
│    0    │ 1  │  'Tech'   │       null       │
│    1    │ 2  │ 'GraphQL' │        1         │
│    2    │ 3  │   'DBs'   │        1         │
│    3    │ 4  │  'APIs'   │        1         │
It returns just the
Tech
category because it's the only one that has subcategories in this dataset. You can read more about
some
,
none
and
every
in the docs here. We also have a dedicated help article about this here.
y
Thank you so much @nikolasburk @Richard Ward