In my Strapi app i have 2 collections types. 1 is called Specialty and the other one is Clinician. 1 Clinician can have multiple Specialty and 1 Specialty belongs to many Clinicians. now when i make API request to get Specialty how do i add the count of total Clinicians that Specialty have?
so rn if i make {{baseURL}}/specialities/1 this will give me
{
"id": 1,
"attributes": {
"speciality": "Psychiatrist",
"createdAt": "2024-03-20T07:16:40.146Z",
"updatedAt": "2024-03-20T11:36:25.587Z"
}
}
and i want something like this
{
"id": 1,
"attributes": {
"speciality": "Psychiatrist",
"clinician_count":23,
"createdAt": "2024-03-20T07:16:40.146Z",
"updatedAt": "2024-03-20T11:36:25.587Z"
}
}
This topic has been created from a Discord post (1242692379966963813) to give it more visibility.
It will be on Read-Only mode here.
Join the conversation on Discord
{{baseURL}}/specialities/1populate=clinicians
but
{{baseURL}}/specialities/1?populate=clinicians
just returning
{
"data": {
"id": 1,
"attributes": {
"speciality": "Psychiatrist",
"createdAt": "2024-03-20T07:16:40.146Z",
"updatedAt": "2024-03-20T11:36:25.587Z"
}
},
"meta": {}
}
without any clinicians informations
in this example they have showed populating category under articles
but in my case i want to get the articles count from category
you see in here when i create a new clinician enrty i can select multiple specialities
this is how i create speciality
so in the clinicians create page
all the speciality i created in here will be listed
You not going to get count
Without custom controller or middleware
So it’s easier to calculate on frontend
so then why did you even suggest that ?populate=clinicians in the first place?
i dont understand
Well you can try just populate=*
populate=* is also same result as this one
and alos populate=deep same
So you don’t have this clinicians in the response, strange
I don’t see clinicians prop here
Also it seems you put your attributes with Uppercase prefix
Its the page to create clinicians with specialities