---
title: "Relations"
slug: "relations"
abstract: "How to query for named parent relationships using a specific ID."
---
# Relations

When filtering on a relation, use the relation name, which is the system name of a relation member defined on an entity definition. The syntax for a relation name is `ParentDefinitionToChildDefinition` (for example, `CategoryToAsset,FinalLifeCycleStatusToAsset`). You can retrieve a relation name using a `GET /api/entitydefinitions/{definitionName}` and examining `member_groups[*].members` for entries where "type": "Relation". The `name` field of each such entry is what goes in a filter. The `.id` is the numeric primary key of the specific entity instance on the other side of the relation (that is, the entity whose children (or parents) you want to retrieve). In the following example, you are filtering assets by `Type = Archive` and excluding assets where the status (`M.Final.LifeCycle.Status`) is `Approved`.

```json
{
    "query": {
      "filter": {
        "type": "Composite",
        "operator": "AND",
        "children": [
          {
            "type": "Definition",
            "operator": "Equals",
            "name": "M.Asset"
          },
          {
            "type": "Relation",
            "relation": "AssetTypeToAsset",
            "parent_id": 7070
          },
           {
            "type": "Not",
            "child": {
                "type": "Relation",
                "relation": "FinalLifeCycleStatusToAsset",
                "parent_id": 544
            }
            }
        ]
      },
      "skip": 0,
      "take": 10,
      "sorting": [
        {
          "field_type": "Property",
          "field": "created_on",
          "culture": "en-us",
          "order": "Desc"
        }
      ]
    },
    "load_configuration": {
      "load_entities": true,
      "property_option": {
        "load_option": "None",
        "properties": []
      },
      "relation_option": {
        "load_option": "Custom",
        "relations": [
          {
            "name": "AssetToAssociatedCollections"
          }
        ]
      },
      "culture_option": {
        "load_option": "All",
        "cultures": []
      }
    }
  }
```


## Parents

You can query for named parent relationships by using a specific ID.

For instance, to query for all assets linked to a certain brand ID:

```http
GET http://<hostname>/api/entities/query?query=Definition.Name=='M.Asset' AND Parent('BrandToAsset').id==331

```

> [!note]
> This property only supports the **\==** operator, but can be [negated](https://doc.sitecore.com/ch/en/developers/cloud-dev/negating.html "Negating").

## Children

You can query for named child relationships by using a specific ID.

For instance, to query for all assets that have another specific asset as child:

```http
GET http://<hostname>/api/entities/query?query=Definition.Name=='M.Asset' AND Child('RelatedAssetsToAsset').id==407

```

> [!note]
> This property only supports the **\==** operator, but can be [negated](https://doc.sitecore.com/ch/en/developers/cloud-dev/negating.html "Negating").

## Ancestors

You can query for named ancestors (secured and unsecured) by using a specific ID.

For instance, to query for all assets that belong to *M.AssetMedia*:

```http
GET http://<hostname>/api/entities/query?query=Definition.Name=='M.Asset' AND Ancestor('AssetMediaToAsset').id==317

```

> [!note]
> This property only supports the **\==** operator, but can be [negated](https://doc.sitecore.com/ch/en/developers/cloud-dev/negating.html "Negating").

## Exists

You can query for named relationships which have a parent entity.

For instance, to query for all assets which have a brand:

```http
GET http://<hostname>/api/entities/query?query=Definition.Name=='M.Asset' AND Exists('BrandToAsset')

```

## Missing

You can query for named relationships which do not have a parent entity.

For instance, to query for all assets which do not have a brand:

```http
GET http://<hostname>/api/entities/query?query=Definition.Name=='M.Asset' AND Missing('BrandToAsset')

```