computed method
Add computed fields (correlated subqueries) to the query.
Computed fields generate subqueries in the SELECT clause that reference the parent row. This is useful for aggregating related data inline.
Example:
.computed({
'minPrice': ComputedField.min('price',
from: 'ConsultationPlan',
where: {'consultantProfileId': FieldRef('id')}),
'priceCurrency': ComputedField.first('priceCurrency',
from: 'ConsultationPlan',
where: {'consultantProfileId': FieldRef('id')},
orderBy: {'price': 'asc'}),
})
Generates SQL like:
SELECT *,
(SELECT MIN("price") FROM "ConsultationPlan"
WHERE "consultantProfileId" = t0."id") AS "minPrice",
(SELECT "priceCurrency" FROM "ConsultationPlan"
WHERE "consultantProfileId" = t0."id"
ORDER BY "price" ASC LIMIT 1) AS "priceCurrency"
FROM "ConsultantProfile" t0
Implementation
JsonQueryBuilder computed(Map<String, ComputedField> fields) {
_computed = fields;
return this;
}