Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Good way to handle relations? #12863

Closed
alexandernanberg opened this issue Mar 26, 2019 · 1 comment
Closed

Good way to handle relations? #12863

alexandernanberg opened this issue Mar 26, 2019 · 1 comment
Labels
type: question or discussion Issue discussing or asking a question about Gatsby

Comments

@alexandernanberg
Copy link
Contributor

Summary

I'm trying to figure out how to handle relations in a good way. I've read some other issues and the documentation but it still haven't "clicked" for me.

So I have a index.md file that looks like this and I want to somehow "pull" content from multiple other markdown files. In this case I use a relative path to reference the other files.

---
title: Lorem ipsum
featured_case:
  - ../case/case-1.md
  - ../case/case-2.md
---

I know it works it the featured_case wouldn't be an array but just the relative path to a file. Is there some straightforward way to enable this for arrays?

Is there another better way to do relations? I feel like using the path is the most robust way, since titles can change etc. And I'm not a big fan of the "mapping" solution, since that field will be added on all files if I'm not mistaken.

Relevant links

https://www.gatsbyjs.org/docs/creating-a-source-plugin/#two-ways-of-adding-relationships-between-nodes

#3129

@coreyward coreyward added the type: question or discussion Issue discussing or asking a question about Gatsby label Mar 26, 2019
@alexandernanberg
Copy link
Contributor Author

This apparently already works. You just have to change the query to be

featured_case {
  childMdx {
    frontmatter {
      title
      tags
    }
  }
}

replace childMdx with childMarkdownRemark if you'r not using MDX

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question or discussion Issue discussing or asking a question about Gatsby
Projects
None yet
Development

No branches or pull requests

2 participants