Relations
List Relations
List all relations that exist in Directus. The data returned in this endpoint will be filtered based on the user's permissions. For example, relations that apply to a collection that the current user doesn't have access to are stripped out.
Query Parameters
Control what fields are being returned in the object.
A limit on the number of objects that are returned.
How many items to skip when fetching data.
What metadata to return in the response.
How to sort the returned items. sort
is a CSV of fields used to sort the fetched items. Sorting defaults to ascending (ASC) order but a minus sign (-
) can be used to reverse this to descending (DESC) order. Fields are prioritized by their order in the CSV. You can also use a ?
to sort randomly.
Select items in collection by given conditions.
Filter by items that contain the given search query in one of their fields.
Cursor for use in pagination. Often used in combination with limit.
GET /relations
{
"data": [
{
"id": 1,
"many_collection": "directus_activity",
"many_field": "user",
"one_collection": "directus_users",
"one_field": null,
"one_allowed_collections": [],
"junction_field": null
}
]
}
Create a Relation
Create a new relation.
Query Parameters
Control what fields are being returned in the object.
What metadata to return in the response.
Request Body
Collection that has the field that holds the foreign key.
Collection on the one side of the relationship.
Foreign key. Field that holds the primary key of the related collection.
Alias column that serves as the one side of the relationship.
Field on the junction table that holds the primary key of the related collection.
POST /relations
{
"data": {
"id": 1,
"many_collection": "directus_activity",
"many_field": "user",
"one_collection": "directus_users",
"one_field": null,
"one_allowed_collections": [],
"junction_field": null
}
}
Retrieve a Relation
Retrieve a single relation by unique identifier.
Query Parameters
Identifier for the object.
Control what fields are being returned in the object.
What metadata to return in the response.
GET /relations/{id}
{
"data": {
"id": 1,
"many_collection": "directus_activity",
"many_field": "user",
"one_collection": "directus_users",
"one_field": null,
"one_allowed_collections": [],
"junction_field": null
}
}
DELETE /relations/{id}
Update a Relation
Update an existing relation.
Query Parameters
Identifier for the object.
Control what fields are being returned in the object.
What metadata to return in the response.
Request Body
Collection that has the field that holds the foreign key.
Collection on the one side of the relationship.
Foreign key. Field that holds the primary key of the related collection.
Alias column that serves as the one side of the relationship.
Field on the junction table that holds the primary key of the related collection.
PATCH /relations/{id}
{
"data": {
"id": 1,
"many_collection": "directus_activity",
"many_field": "user",
"one_collection": "directus_users",
"one_field": null,
"one_allowed_collections": [],
"junction_field": null
}
}