Fetch Linked Document Fields

You can use the fetchLinks option to add additional fields in a linked document to the query results. To learn more about this option checkout the How Query Predicates Work page.

Query for the recipe with the uid “chocolate-chip-cookies”. If the custom type “recipe” has a link to another custom type “author”, then you can pull in certain fields from that linked document, in this case the “name” field.

Copy
      api.getByUID('recipe', 'chocolate-chip-cookies',
    {'fetchLinks': 'author.name'}
).then(function(document) {
    var author = document.getLink('recipe.author-link');
    // variable author now works like a top-level document
    var authorName = author.getText('author.name');
    console.log(authorName);
});
    
Copy
      $document = $api->query(
    Predicates::at('my.recipe.uid', 'chocolate-chip-cookies'),
    [ 'fetchLinks' => 'author.name' ]
)->getResults()[0];
$author = $document->getLink('recipe.author-link');
// $author now works like a top-level document
$authorName = $author->getText('author.name');
// $authorName contains the text from the field "name"
    
Copy
      document = api.query(
    Prismic::Predicates.at("my.recipe.uid", "chocolate-chip-cookies"),
    { "fetchLinks" => "author.name" }
).results[0]

author = document["recipe.author-link"]
# author now works like a top-level document

author_name = author["author.name"].value
# author_name contains the text from the field "name"