Fetch records from a single link reference

Hi!
I have to modals:

  • Articles: with 3 fields: title, link and language (this is a single link field referenced to the next model)
  • Article Language: with 2 fields: code and name.

I would like to fetch all articles from an specific language, but I don’t know how to do it.

query MyQuery {
  allArticles(filter: {language: {in: "English"}}) {
    id
    language {
      code
      name
   }
  }
}

Thanks

You don’t need a secondary model to handle languages, you can do this instead:

{
  onlyPostsInEnglish: allPosts(locale: en, filter: {title: {isBlank: false}}) {
    title
    ...
  }
}

This returns all the posts that have a content in English, and the title in English.

If that’s what you need, you can also retrieve the title for ALL languages (that is, maybe the same post in English has a translation in Chinese), like this:

{
  onlyPostsInEnglish: allPosts(locale: en, filter: {title: {isBlank: false}}) {
    title
    ...
    _allTitleLocales {
      value
      locale
    }
  }

Hope this helps!

Hi @s.verna !
Thanks for your quickly answer!
I’m using a secondary modal because I’d like to make the title required but not translatable. I don’t want multilanguage posts and if I make title required and translatable, I have to translate the title in every language. For that reason I create a secondary model for languages, to decide in which language you want to asign this article.

Related to the same question, I also have a modal Article Category and I don’t know how to fetch all articles of an especific category… :sob: