fetchLinks not working for me?

Hi I'm trying to pull through a country that I've associated with my document. As I understand fetch links should do that?

Here is my code:

async asyncData({ $prismic, params, error }) {

try{

  // Query to get post content

  const document = (await $prismic.api.getByUID('photo', params.uid, { fetchLinks: 'country.name' })).data



  // Returns data to be used in template

  return {

    document,

                

  }

} catch (e) {

  // Returns error page

  error({ statusCode: 404, message: 'Page not found' })

}

}

}

And then in the template:

{{ $prismic.asText(document.country.name) }}

Any ideas?

Hey @richardarran, welcome to the Community!

Fetch Links will help you retrieve content from linked documents. In your case, it should work if you have a photo Custom Type with a Content Relationship (AKA Document Link) field with the API ID country which links to a document of the type country. Then, Inside the country document, you have a Key Text field with the API ID name.

Is this how your documents look like?

Hi, thanks for your response.

Here is my photo custom type and country custom type

{
"Main": {
"uid": {
"type": "UID",
"fieldset": "Unique Identifier",
"config": {
"placeholder": "UID"
}
},
"date": {
"type": "Date",
"fieldset": "Date Added"
},
"title": {
"type": "StructuredText",
"fieldset": "Photo Title",
"config": {
"single": "heading1",
"placeholder": "Title..."
}
},
"categories": {
"type": "Group",
"fieldset": "Categories",
"config": {
"fields": {
"link": {
"type": "Link",
"config": {
"select": "document",
"customtypes": [
"category"
],
"placeholder": "Link to a category"
}
}
}
}
},
"country": {
"type": "Link",
"config": {
"select": "document",
"customtypes": [
"country"
],
"label": "Country"
}
}
},
"Photo Info": {
"image": {
"type": "Image",
"fieldset": "Photo"
},
"price": {
"type": "Number",
"fieldset": "Price",
"config": {
"label": "USD",
"min": 1,
"placeholder": "Insert Price..."
}
},
"description": {
"type": "StructuredText",
"config": {
"multi": "paragraph,preformatted,heading1,heading2,heading3,heading4,heading5,heading6,strong,em,hyperlink,image,embed,list-item,o-list-item,rtl",
"label": "Photo Description",
"placeholder": "Description..."
}
}
}
}

{
"Main" : {
"uid" : {
"type" : "UID",
"config" : {
"label" : "ID",
"placeholder" : "Enter an SEO friendly unique ID"
}
},
"name" : {
"type" : "StructuredText",
"config" : {
"single" : "heading1,heading2,heading3,heading4,heading5,heading6",
"label" : "name",
"placeholder" : "Country name"
}
},
"description" : {
"type" : "StructuredText",
"config" : {
"multi" : "paragraph,preformatted,heading1,heading2,heading3,heading4,heading5,heading6,strong,em,hyperlink,image,embed,list-item,o-list-item,rtl",
"label" : "Description",
"placeholder" : "Enter a country description"
}
}
}
}

@Paulina is what I have correct?

Fixed it! I simply needed to add .data

This works document.country.data.name

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.