Unsure how to implement One-to-Many content relationship

I come from a backend development background and I’m not how to implement this content structure in hugo.

I have projects and logs. Every project has many logs / each log has one project. On my project single page, I want to be able to retrieve all logs for that specific project. Does anyone have any suggestions on how to accomplish this?

Thanks!

So your content looks like this:

content/
├── projects/
│   ├── project-1.md
│   ├── project-2.md
│   └── project-3.md
└── _index.md

What are “logs”? Will each log have its own page? Are the logs in a data file? Remote?

Logs have their own pages and index. When a new log is created, I would like to associate it with a specific project so I can display all associated logs for a specific project.

content/
├── projects/
│   ├── project-1.md
│   ├── project-2.md
│   └── project-3.md
├── logs/
│   ├── log-1.md
│   ├── log-2.md
│   └── log-3.md
└── _index.md

I thought about adding an id field to the front matter of a project and then in the front matter of each log. I’d also have a field project-id. I wasn’t sure if there was a better solution than to query that way.

Example:
project markdown

title: "Project 1"
id: 10

log markdown

title: "My project 1 log!"
project_id: 10

Since each log can only have one parent, you could also use a section page for each project, then the logs are children – no need for IDs.

content/projects/
├── project-1/
│   ├── _index.md
│   ├── log-1.md
│   └── log-2.md
└── project-2/
    ├── _index.md
    ├── log-3.md
    └── log-4.md

If you need all the logs in one section, then adding the IDs as you suggested above is probably the right approach. If you do this, be sure to look into Related Content.

1 Like

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