I was able to get some nested data using the following:
api/booking/controllers/booking.js:
async find(ctx) {
const entities = await strapi.services.booking.find(ctx.query, [
'class',
'class.capacity',
'class.date',
'class.category',
'class.category.name',
'class.type',
'class.type.name',
'class.startTime',
'class.endTime',
]);
}
return entities.map((entity) =>
sanitizeEntity(entity, { model: strapi.models.booking }),
);
},
where my booking
has a relation to class
and user
. So, by default it just comes back with the class id
's - but I'd like to be able to see fields from the class
relation all in the same payload.
ie, instead of this:
user: "123eqwey12ybdsb233",
class: "743egwem67ybdsb311"
I'm trying to get:
user: {
id: "123eqwey12ybdsb233",
email: "foo@bar.com",
...
},
class: {
id: "743egwem67ybdsb311",
capacity: 10,
type: {
name: "Individual",
description: "..."
...
}
...
}
Now, the above works for non-relational fields.. but for fields that are a relation of a relation (ie. class.category
and class.type
), it doesn't seem to work as I would've expected.
In my database, the relation chain is like so: booking
-> class
-> category
/ type
, where category
and type
each have a name
and some other fields.