Count Relations
count
query parameter allows clients to include the count of related resources in the API response. This feature is designed for one-to-many or many-to-many relationships, providing the total number of associated records for specified relations. The count is returned in a {relation_name}_count
field for each specified relation.Usage
count
parameter supports two formats:1.
?count=relation1,relation2
2.
?count[]=relation1&count[]=relation2
Response Field
{relation_name}_count
. This field will contain the total number of related records for that relation.Examples
Single Relation Count
assignments
:GET /api/customer?count=assignments
{
"id": 1,
"name": "Example Customer",
"assignments_count": 5
}
Multiple Relation Counts
assignments
and contracts
:GET /api/customer?count=assignments,contracts
{
"id": 1,
"name": "Example Customer",
"assignments_count": 5,
"contracts_count": 3
}
Array-style Query
GET /api/customer?count[]=assignments&count[]=contracts
Valid Relations
count
parameter must be one-to-many or many-to-many relationships. If a field is not a valid relation or does not meet these criteria, the API will return a 400 Bad Request
response with an appropriate error message.Summary
count
parameter to include the count of related resources in API responses.{relation_name}_count
field.count
parameter, you can retrieve aggregate information about related resources efficiently, minimizing the need for additional API calls.Modified at 2025-01-26 14:28:43