I think I am being super dumb, but I have a many-t...
# orm-help
a
I think I am being super dumb, but I have a many-to-many relationship of
Entry
to
Campaign
. I want to find all entries connected to a given campaign. I thought I could just do
Copy code
const entries = await ctx.prisma.entry.findMany({
  where: {
    campaigns: { every: { id: { equals: campaignId } } },
  },
});
but this is returning entries that aren’t connected to any campaigns as well 😕 According to the docs this should only return every
Entry
that has a
Campaign
with the given id, or am I wrong? I can solve this by adding
some: {}
to the filter (to exclude every
Entry
without a
Campaign
, but this seems unnecessary to me)
1
t
You can just search for the entries where the campaignId relation scalar field equals the id of the campaign you’re looking for. For example:
Copy code
const entries = await prisma.entry.findMany({
  where: { campaignId: 5 }
});
n
Hi @Amos Bastian 👋 This is the expected behaviour, please see this comment on the related GitHub Issue, The workaround that you have implemented of adding
some:{}
before the
every
clause is ideal and should work.
We also have a docs issue so that we can clear out this confusion.
a
Ah thanks for the clarification. Good to see the docs will be improved. Funny to see someone else posted the same solution in the thread 20h ago 😛
👍 1