hi all, i am trying to figure out the simplest str...
# orm-help
t
hi all, i am trying to figure out the simplest structure for data entry for my application. I am building past setlists for concerts, so my models look like this:
Copy code
type Song @model {
  id: ID! @isUnique
  name: String!
}

type ConcertSong @model {
  id: ID! @isUnique
  song: Song @relation(name: "Songs")
  concerts: [ConcertSong!]! @relation(name: "ConcertSongs")
}

type Concert @model {
  id: ID! @isUnique
  venue: Venue! @relation(name: "ConcertVenue")
  start: DateTime!
  setlist: [ConcertSong!]! @relation(name: "ConcertSongs")
  opener: Artist 
}
data entry will be adding a bunch of songs, then a bunch of concerts, then a bunch of ConcertSong's... is there a way to add ConcertSongs without having to find the id (something more human readable). also, is there a better way to do a bunch of data entry like this than mutations? there will likely be hundreds of concerts and songs. Thanks!
h
To make it more human readable you can add a slug field derived from name and it will be unique
t
ok, and then in the mutation, just look them up by the slug on the backend when creating?
h
In your model I am not really sure about this
concerts: [ConcertSong!]!
Is this right for the thing you are trying to achieve
t
very new to graphql, just trying to get a good general direction
h
Yes you can use any slugify package to convert name to slug from the name
t
i was under the impression that every relation needed to be set in each model right?
concerts would be all the concerts that that song has been played at
h
Yes you can set it up but I am not sure that it should be ConcertSong , it should be Concert as seen in your model
t
oh woops yea
h
Ok then this model is absolutely fine :) for your use case
t
awesome - thanks so much!
h
Also I am not sure that @isUnique works, from all the docs I see it is @unique
But I'd recommend anyways to make your code streamlined with the docs
@tim