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?