Show examples in:
Javascript HTTP
Content Management API > Model/Block model

List models referencing another model/block

Returns all models that reference the specified item type, either directly through fields or indirectly through nested blocks.

For Block Models (modular_block: true)

Returns all models that can embed the specified block model, including:

Direct embedding via:

  • rich_text fields (Modular Content) — specified in the rich_text_blocks validator
  • single_block fields — specified in the single_block_blocks validator
  • structured_text fields — specified in the structured_text_blocks or structured_text_inline_blocks validators

Indirect embedding:

  • Models that embed other block models, which themselves contain fields that can embed the target block (recursive traversal through nested block structures)

For Regular Models (modular_block: false)

Returns all models that reference the specified model, including:

Direct references via:

  • link fields (Single link) — specified in the item_item_type validator
  • links fields (Multiple links) — specified in the items_item_type validator
  • structured_text fields — specified in the structured_text_links validator

Indirect references:

  • Models that embed block models containing fields that reference the target model (traversal through nested block structures to find references within blocks)

Query parameters

fields object

Sparse fieldsets: for each entity type, the attributes and the relationships to return, separated by commas. Each entity declares its attributes and its relationships in its own schema.

item_type string

Attributes and relationships to return for each item_type that this endpoint returns.

Example: "name,api_key,collection_appearance,singleton_item"

Returns

Returns an array of resource objects of type item_type

Examples

import { buildClient } from "@datocms/cma-client-node";
async function run() {
const client = buildClient({ apiToken: process.env.DATOCMS_API_TOKEN });
const modelIdOrApiKey = "blog_post";
const itemTypes = await client.itemTypes.referencing(modelIdOrApiKey);
for (const itemType of itemTypes) {
// Check the 'Returned output' tab for the result ☝️
console.log(itemType);
}
}
run();
{
id: "DxMaW10UQiCmZcuuA-IkkA",
name: "Blog post",
api_key: "post",
singleton: false,
sortable: true,
modular_block: false,
tree: false,
ordering_direction: null,
ordering_meta: "created_at",
draft_mode_active: false,
all_locales_required: false,
collection_appearance: "compact",
hint: "Blog posts will be shown in our website under the Blog section",
inverse_relationships_enabled: false,
draft_saving_active: false,
meta: { has_singleton_item: false },
singleton_item: null,
fields: [{ type: "field", id: "Pkg-oztERp6o-Rj76nYKJg" }],
fieldsets: [{ type: "fieldset", id: "93Y1C2sySkG4Eg0atBRIwg" }],
presentation_title_field: null,
presentation_image_field: null,
title_field: null,
image_preview_field: null,
excerpt_field: null,
ordering_field: null,
workflow: null,
}