I use objextion.js and knex on project.
And I wanna select two properties from relation and and nest them in an array. That relation contains array of object with properties lat and lng, I need receive array of arrays with lat and lng [[lat, lng]]
. How I understand I must select fields and use raw from objection to write array_agg for contain my props, but I don't understand what syntax there must be.
In modifyGraph with select I receive array of objects with lng and lat
My request
const query = Restaurants
.query()
.withGraphFetched({
schedule: true,
})
.skipUndefined();
if (lat && lng) {
query.withGraphFetched({
areas: {
area: {
coordinates: true,
},
},
}).modifyGraph('areas.area.coordinates', (builder) => {
builder.select([
'lat',
'lng',
]);
});
}
return query
.andWhere(restFields)
.andWhere('name', 'ilike', `%${search}%`);
};
My response from db
[
AreasCoordinatesModel { lat: -46.653, lng: -23.543 },
AreasCoordinatesModel { lat: -46.634, lng: -23.5346 },
]
And must be
[
[ -46.653, -23.543 ],
[ -46.634,-23.5346 ]
]