-1

Well in objection you can use withGraphFetched to help build an object structured view of a database.

Considering a mandate that belongs to a customer, one would (after defining the model correctly) call it like:

const mandates = await MandateModel
    .query(db)
    .withGraphFetched('_customer');

Which works quite well. However now I wish to select "all mandates belonging to customer XYZ". I notice it is possible to add a select to the withGraphFetched:

const mandates = await MandateModel
    .query(db)
    .withGraphFetched('_customer(isCustomer)')
    .modifiers({
        isCustomer(builder) {
            builder.where('key', custId)
        }
    });

However this just makes the customer field null when there are no customers. - However can I modify the query so it does a proper join-check? Yet does return in the correct structure?

paul23
  • 8,799
  • 12
  • 66
  • 149

1 Answers1

1

May be you can try something like below,

const mandates = await MandateModel.query(db)
.withGraphJoined('_customer')
.whereIn('_customer.key', custId)

See this link for further reference.

ketan shinde
  • 212
  • 2
  • 10