Answers.Body: <p>I'm not sure of your exact setup, but you can get the relationships dynamically and make them part of your dynamic subpath.</p>
  <p>Let's assume you have the following channel sections:</p>
  <ul>
  <li>Episodes</li>
  <li>Seasons</li>
  <li>Shows</li>
  </ul>
  <p>In the field layout for Episodes, you have an Entries field, where you choose which season it belongs to, and an Assets field, where you upload the video file.</p>
  <p>The Season entry (e.g., Season 1) has a Show Entries field where you relate the show.</p>
  <p>When you create a new episode, you choose the season and get the show automatically based on the season's relationship to it, and you upload a video file for that episode.</p>
  <p>With that setup, you can input some Twig code in the Default Upload Location to create a dynamic subpath of <code>show/season/episode</code> like this (I'm using slugs instead of IDs):</p>
  <pre><code>{{ object.season.one().show.one().slug }}/{{ object.season.one().slug }}/{{object.slug}}
  </code></pre>
  <p><a href="https://i.sstatic.net/SELa9.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/SELa9.png" alt="how path looks in Assets sidebar" /></a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-11-18T15:39:19.660Z
Answers.Text: Thank you for taking the time! This is exactly what I needed. I'm a former CQ subscriber, and hope to be again soon.
Answers.UserDisplayName: Jim
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-11-16T23:43:43.717Z
Answers.LastActivityDate: 2022-11-16T23:43:43.717Z
Answers.UserDisplayName: CraftQuest
Body: <p>My goal is to ensure uploaded videos are organized into folders like:</p>
  <pre><code>/Show/Season/Episode/videofile.mp4 
  </code></pre>
  <p>Or stated another way...</p>
  <pre><code>/{{ Show ID of grandparent }}/{{ Season ID of parent }}/{{ Episode ID of parent}}/videofile.mp4
  </code></pre>
  <p>I understand we can use twig tags to dynamically control the subfolder names, but since our Videos entries are related children of Episodes, which is a child of Seasons, which is a child of Shows, how do I ensure these values are used in the path? As it stands I've organized these as separate sections, where entry fields are used to select the children (Seasons, Episodes, videos). But I'm questioning whether this should be collapsed into one Shows section with a matrix for including Seasons, Episodes, and Videos.</p>
  <p>Using Craft 4</p>
  
Tags: <assets><craft4><filesystem><volumes>
Title: How to enforce subfolder names for uploaded assets in hierarchical related sections
ThreadText: # How to enforce subfolder names for uploaded assets in hierarchical related sections
  
  (Asked by: username_0 on 2022-11-11)
  
  My goal is to ensure uploaded videos are organized into folders like:
  
  ```
  /Show/Season/Episode/videofile.mp4 
  
  ```
  
  Or stated another way...
  
  ```
  /{{ Show ID of grandparent }}/{{ Season ID of parent }}/{{ Episode ID of parent}}/videofile.mp4
  
  ```
  
  I understand we can use twig tags to dynamically control the subfolder names, but since our Videos entries are related children of Episodes, which is a child of Seasons, which is a child of Shows, how do I ensure these values are used in the path? As it stands I've organized these as separate sections, where entry fields are used to select the children (Seasons, Episodes, videos). But I'm questioning whether this should be collapsed into one Shows section with a matrix for including Seasons, Episodes, and Videos.
  
  Using Craft 4
  
  **Tags:** assets, craft4, filesystem, volumes
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2022-11-16. Score: 1 | Accepted answer
  
  I'm not sure of your exact setup, but you can get the relationships dynamically and make them part of your dynamic subpath.
  
  Let's assume you have the following channel sections:
  
  * Episodes
  * Seasons
  * Shows
  
  In the field layout for Episodes, you have an Entries field, where you choose which season it belongs to, and an Assets field, where you upload the video file.
  
  The Season entry (e.g., Season 1) has a Show Entries field where you relate the show.
  
  When you create a new episode, you choose the season and get the show automatically based on the season's relationship to it, and you upload a video file for that episode.
  
  With that setup, you can input some Twig code in the Default Upload Location to create a dynamic subpath of `show/season/episode` like this (I'm using slugs instead of IDs):
  
  ```
  {{ object.season.one().show.one().slug }}/{{ object.season.one().slug }}/{{object.slug}}
  
  ```
  
  [![how path looks in Assets sidebar](https://i.sstatic.net/SELa9.png)](https://i.sstatic.net/SELa9.png)
  
  > **Comments:**
  > **username_0**: Thank you for taking the time! This is exactly what I needed. I'm a former CQ subscriber, and hope to be again soon.  
  
  ---
  
  