Is it possible to filter relation specific id? I s...
# orm-help
p
Is it possible to filter relation specific id? I see that there are every and some keywords but I cannot acheive my intention. For example, this query
Copy code
prisma.transaction.findMany({
        skip,
        take,
        where: {
          audience,
          AND: [
            {
              accounts: {
                some: {
                  id: accountId,
                },
              },
            },
            {
              balance: {
                some: {
                  accountId,
                },
              },
            },
          ],
        },
        orderBy,
        include: {
          balance: true,
          transfer: true,
          payout: true,
          fees: true,
          fund: true,
        },
      });
    }
gives me
Copy code
{
  "data": {
    "transactions": [
      {
        "id": "ckqtnygnv0032z5vhbb04b2kh",
        "type": "TRANSFER",
        "description": "test transfer",
        "transfer": {
          "id": "ckqtnygnv0035z5vhthw2z65e",
          "payee": {
            "username": "justin",
            "id": "ckqtn3kv70003ccvh1ufbyoxv"
          },
          "payor": {
            "id": "ckqtne3lm0128ccvhmpiz9c26",
            "username": "dustin"
          }
        },
        "fund": null,
        "balance": [
          {
            "id": "ckqtnygnv0033z5vhdlen44um",
            "amount": 5000,
            "account": {
              "id": "ckqtn3kv70003ccvh1ufbyoxv",
              "username": "justin"
            }
          },
          {
            "id": "ckqtnygnv0034z5vhvwwbr0z2",
            "amount": -5000,
            "account": {
              "id": "ckqtne3lm0128ccvhmpiz9c26",
              "username": "dustin"
            }
          }
        ]
      }
    ]
  }
}
But for balance entity, I only want to query balance.account.id == “ckqtn3kv70003ccvh1ufbyoxv” If i change this part to
Copy code
{
              balance: {
                some: {
                  accountId,
                },
              },
            }
to this (some to every):
Copy code
{
              balance: {
                every: {
                  accountId,
                },
              },
            }
I get empty array… is there anything similar like
Copy code
balance: {
  accountId = "account id I want to query "
}
r
You would need to do this:
Copy code
prisma.transaction.findMany({
        skip,
        take,
        where: {
          audience,
          AND: [
            {
              accounts: {
                some: {
                  id: accountId,
                },
              },
            },
            {
              balance: {
                some: {
                  accountId,
                },
              },
            },
          ],
        },
        orderBy,
        include: {
          balance: { where: { accountId = "some-id" } },
          transfer: true,
          payout: true,
          fees: true,
          fund: true,
        },
      });
👍 1
😍 1
p
thats it!! thank you!! i didnt notice that we can use where in include. Thank you
🙌 1