I tend to model things like this with Dicts, Sets, and a type alias for 
each identifier. So, something like

type alias Model =
  { artists : Dict ArtistId Artist
  , albums : Dict AlbumId Album
  }


type alias ArtistId =
  Int


type alias Artist =
  { id : ArtistId
  , name : String
  , albums : Set AlbumId
  }


type alias AlbumId =
  Int


type alias Album =
  { id : AlbumId
  , name : String
  , artists : Set ArtistId
  }

This is optimized for querying, adding and updating both Artists and 
Albums. Deletions require a bit more thought: You'll have to update all the 
cross-reference Set's as well.

On Thursday, September 22, 2016 at 6:24:38 PM UTC-4, Dénes Harmath wrote:
>
> Hi everybody,
>
> in a typical model, there are cross-references: e.g. we have artists and 
> albums, and the album refers to its artist. How do we model this in Elm? A 
> possible approach is giving unique identifiers to objects and store the 
> referred object's identifiers similar to the TodoMVC example - is this 
> mechanism extracted to some library in a type-safe way?
>
> Thank you in advance,
> thSoft
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to