Where with a joined table

Hello guys I’ve a problem here… I cant use a where in this case, look

 const query = Transaction.query()

     query.with("account", (builder) => {
        builder
          .select(["id", "name", "account_number", "agency", "bank_id", "enterprise_id"])
          .with("enterprise", (builder) => {
            builder.select(["id", "name"]);
          });
        builder.wherePivot('user_id', auth.user.id)
        builder.with("bank")
      })

await query.fetch()

I receive that error builder.wherePivot is not a function

I need to show only the transactions for the accounts that have the user I logged int, how could I do that?

1 Like

try like that

 const query = Transaction.query()

     query.with("account", (builder) => {
        builder
          .select(["id", "name", "account_number", "agency", "bank_id", "enterprise_id"])
          .with("bank")
          .with("enterprise", (builder) => {
            builder.select(["id", "name"]);
          }).wherePivot('user_id', auth.user.id)
      })

await query.fetch()
2 Likes

It could work, but I solved it using a subquery!

1 Like