Hey! Have a question, how should I create the quer...
# orm-help
r
Hey! Have a question, how should I create the query to replace "exists" in prisma. I haven't found anything related to this topic in the documentation. Example: SELECT * FROM
table1
WHERE
id
=
1
AND EXISTS (SELECT * FROM
table2
WHERE
contacts
.
id
= 3)
r
@rcastell 👋 Are the tables related in Prisma?
r
Yes they are related
@Ryan
r
Could you share your schema?
r
This is an example the query that i should generate or replace
@Ryan Thanks for response 👍
r
In this case, do you want to check if the contract exists for the given rate?
r
yes, at the same time check if that contract has no relation with "contract_user_restriction"
How could i check if relation exists(contract)?
r
Could you try something like this:
Copy code
await prisma.rate.findFirst({
  where: { 
    id: 1,
    contracts: { id: 3 },
  },
})
r
returns null
r
This is an
AND
condition, so both of the conditions need to match
r
Ok im having an idea of how to solve it, thanks!
👍 1
This was the way i found to know if a reltion exists or not
To know if not exists
Copy code
await prisma.rate.findFirst({
  where: { 
    id: 1,
    contracts: { none: {} },
  },
})
and know if exists
Copy code
await prisma.rate.findFirst({
  where: { 
    id: 1,
    contracts: { some: {} },
  },
})
@Ryan thanks for your help