title: Many-to-many relationship where one entity has multiple properties of the same type
body: <p>I'm not sure how to phrase this, which may be why I couldn't find any information, but I have a many-to-many relationship where one of the entities has multiple properties of many of the other.</p>
  <p>For instance, take the <code>Artist</code> and <code>Song</code> relationship. One artist can have many songs, and one song can have many artists. BUT, a song can have (many) main artists, (many) featured artists and (many) album artists. So these all come from the same table, but I'm not sure how to model this.</p>
  <p>In code, I am using GRDB in Swift, so I follow <a href="https://github.com/groue/GRDB.swift/blob/master/Documentation/AssociationsBasics.md#hasmanythrough" rel="nofollow noreferrer">the docs</a> with:</p>
  <pre><code>import GRDB
      
  struct Artist: TableRecord {
      let id: Int
      let name: String
      ...
      
      static let artistSong = hasMany(ArtistSong.self)
      static let songs = hasMany(Song.self, through: artistSong, using: ArtistSong.song)
  }
  
  struct ArtistSong: TableRecord {
      static let artist = belongsTo(Artist.self)
      static let song = belongsTo(Song.self)
  }
  
  struct Song: TableRecord {
      let id: Int
      let name: String
      ...
      
      static let artistSong = hasMany(ArtistSong.self)
      static let artists = hasMany(Artist.self, through: artistSong, using: ArtistSong.artist)
  }
  </code></pre>
  <p>I imagine this would be fine if there were simply only &quot;artists&quot; on a song. But I have 3 different types of artists for a song (main, featured, album artist) but they all come from the same Artist table.</p>
  <p>What would be the best way to tackle this?</p>