I’m having a problem trying to query over relation...
# orm-help
g
I’m having a problem trying to query over relations, e.g.
Copy code
const item = await ctx.db.query.item({
   where: { product: { id: productId } }
});
I get the error
Reason: 'product' Field 'product' is not defined in the input type 'ItemWhereUniqueInput'.
Is there some way to have relations included in
ItemWhereUniqueInput
? This currently looks like:
Copy code
type ItemWhereUniqueInput {
  id: ID
}
m
Hi! Is the relation a 1 to 1 relation?
g
one to many i.e.
type Product { items: [Item!]! }
m
In other words, many items may have the same product id?
g
nope, each item has one product id
it represents a shopping cart item
n
use
db.query.items
instead of
db.query.item
šŸ‘ 1
item
only offers unique where selectors
m
That's what I was getting at.šŸ˜›
šŸ‘ 1
n
in your case only
id: ID! @unique
g
ah ok, so items will give me
ItemWhereInput
n
correct
and returns
[Item!]!
not
Item
g
Thank you, have been stuck on that for some time! šŸ˜…
šŸ™Œ 1
m
@nilan, I was just about to experiment to see whether 1-to-1 relations would show up in a WhereUnique input. Do you recall off the top of your head?
n
no, it doesn't
šŸ‘ 1
this touches on a bigger topic of advanced and combined foreign key constraints/unique constraints which is not yet supported in Prisma
m
Yes sir, that's exactly what I figured.