title: Multiple Nested Domains Over Multiple Forms in Grails
body: <p>I am new to grails and trying to build a small application which has some one to many relationships and I am stuck.</p>
  
  <p>So there are three domain classes Artist, Album and Song.  The intention is a doubly nested 1->m relationship:</p>
  
  <p>An Artist can have many Albums and an Album can have many songs.</p>
  
  <pre><code>class Artist {
  
      List albums = new ArrayList()
  
      static hasMany = [albums: Album]
  
      String artistName
  
      static mapping = {
          albums cascade:"all-delete-orphan"
      }
  }
  
      class Album {
  
      String albumName
      String albumDescr
  
      static belongsTo = [artist: Artist]
  
      List songs = new ArrayList()
      static hasMany = [songs: Song]
  
      boolean deleted
      static transients = [ 'deleted' ]
  
  
       static mapping = {
  
           songs cascade:"all-delete-orphan"
      }
  }
  
      class Song{
  
      Album album
      static belongsTo = [album: Album]
      String songName
      Integer trackNumber
  
      boolean deleted
      static transients = [ 'deleted' ]
  }
  </code></pre>
  
  <p>I would like to use a series of forms to handle the input of data.  In the first view an Artist would be created with any associated Albums.  This view would be similar to the 
  views described here: <a href="http://omarello.com/2010/08/grails-one-to-many-dynamic-forms/" rel="nofollow noreferrer">http://omarello.com/2010/08/grails-one-to-many-dynamic-forms/</a></p>
  
  <p>On submission of the form the Artist and associated Albums would be saved (something like the following)</p>
  
  <pre><code> def artist = new Artist(params)
   artistGroup.save()
  </code></pre>
  
  <p><strong>Here is the part I need help with...</strong></p>
  
  <p>The next view would display the Albums created with the previous view and prompt the user to add the Song information for each.  Upon submission of this form
  the Songs would be saved.</p>
  
  <p>I was thinking I would pass the saved albums in flash scope </p>
  
  <pre><code> flash.myAlbums = artist.albums
  </code></pre>
  
  <p>so they could be displayed in the second view.  However, showing the name of the album is only part of the story, as we will need the Album.id in order to save each of the 
  Songs (and correctly associate its Album).  How can this ID be passed effectively into the second view so that it can be used to save each Song correctly upon submission of the second form?  I have seen this <a href="https://stackoverflow.com/questions/13046539/grails-creating-multiple-nested-objects-inside-single-form">post</a> and it does relate but it does not try to break up saving the data into multiple view.  </p>
  
  <p>I hope this question makes some sense and I appreciate any feedback...including alternate approaches for this.  </p>