Cirqll Core
HomeCirqll
HomeCirqll
  1. Query Parameters
  • Query Parameters
    • Eager Loading
    • Partial Data
    • Count Relations
    • Pagination
      • Filter
      • Order By
  • Authentication
    • OAuth2
      • Authorize
        • Authorize
      • User
        • Me
      • Client
        • Index
        • Create
        • Update
        • Delete
      • Token
        • Create
        • Refresh
        • Index
      • Scopes
  • User
    • Index
      GET
    • Show
      GET
    • Create
      POST
    • Update
      PATCH
    • Delete
      DELETE
  • Role
    • Index
      GET
    • Show
      GET
    • Create
      POST
    • Update
      PATCH
    • Delete
      DELETE
  • Customer
    • Index
      GET
    • Show
      GET
    • Create
      POST
    • Update
      PATCH
    • Delete
      DELETE
  • Contact
    • Index
      GET
    • Show
      GET
    • Create
      POST
    • Update
      PATCH
    • Delete
      DELETE
  • Appointment
    • Index
    • Show
    • Create
    • Update
    • Delete
  • Task
    • Index
    • Show
    • Create
    • Update
    • Delete
  • Financial
    • Chance
      • Index
      • Show
      • Create
      • Update
      • Delete
    • Assignment
      • Index
      • Show
      • Create
      • Update
      • Delete
    • Contract
      • Index
      • Show
      • Create
      • Update
      • Delete
  • Email
    • Index
    • Show
    • Create
    • Update
    • Delete
  • Field
    • Index
    • Show
    • Create
    • Update
    • Delete
  • Note
    • Index
    • Show
    • Create
    • Update
    • Delete
  • To-do
    • Index
    • Show
    • Create
    • Update
    • Delete
  • Template
    • Index
    • Show
    • Update
    • Create
    • Delete
  • Setting
    • Index
    • Update
  • Webhook
    • Index
    • Show
    • Create
    • Update
    • Delete
  1. Query Parameters

Count Relations

The 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#

The count parameter supports two formats:
1.
Comma-separated list:
?count=relation1,relation2
2.
Array-style query:
?count[]=relation1&count[]=relation2

Response Field#

For each specified relation, the API will include a field in the response with the format {relation_name}_count. This field will contain the total number of related records for that relation.

Examples#

Single Relation Count#

To include the count of a single relation, such as assignments:
GET /api/customer?count=assignments
Response:
{
  "id": 1,
  "name": "Example Customer",
  "assignments_count": 5
}

Multiple Relation Counts#

To include the count of multiple relations, such as assignments and contracts:
GET /api/customer?count=assignments,contracts
Response:
{
  "id": 1,
  "name": "Example Customer",
  "assignments_count": 5,
  "contracts_count": 3
}

Array-style Query#

You can also specify relations using an array-style query:
GET /api/customer?count[]=assignments&count[]=contracts
This will produce the same result as the comma-separated example above.

Valid Relations#

The relations specified in the 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#

Use the count parameter to include the count of related resources in API responses.
Specify relations as a comma-separated list or an array-style query.
The count for each relation is returned in a {relation_name}_count field.
By leveraging the 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
Previous
Partial Data
Next
Pagination
Built with