Hello, I'm new to Prisma and have a question about...
# orm-help
j
Hello, I'm new to Prisma and have a question about many to many relation tables. I have two tables
Releases
and
Artists
that have a m-n relationship. I would just put and
Artist[]
column on releases and
Releases[]
on artists but I want to have the artist's role associated with the
Release
. So I made a table
ArtistsOnReleases
. It has columns:
Copy code
model ArtistsOnReleases {
  artist    Artist   @relation(fields: [artistId], references: [id])
  artistId  Int
  release   Release  @relation(fields: [releaseId], references: [id])
  releaseId Int
  role      Role     @default(MAIN)
  createdAt DateTime @default(now())

  @@id([artistId, releaseId])
}
I want to know how to seed it basically. RN I .create() my two artists and then for each artist I say:
Copy code
const artistOneJoin = prisma.artistsOnReleases.create({
      data: {
        artistId: 1,
        releaseId: 1,
        role: "REMIXER"
      }
    })
but when I query for artistsOnReleases by artistID equals 1 I don't get anything returned. I figure this will apply to my mutations for releases as well so I want to get the seeding figured out.
I checked in psql and
SELECT * FROM "ArtistsOnReleases";
returns
(0 rows)
Basically solved by:
Copy code
const album = await prisma.release.create({
    data: {
        name: "album",
        releaseDate: new Date(),
        image: "",
        type: "SINGLE",
        url: "",
        artists: {
          create: [{ name: 'artist', artistsOnReleases: {
            create: {
              role: "MAIN",
              releaseId: 1
            }
          } } , { name: 'artist2',  artistsOnReleases: {
            create: {
              role: "MAIN",
              releaseId: 1
            }
          }
          }]
        },
        tags: {
            create:[{
                name: "kunq"
            }]
        },
    }
  })
It's not perfect bc the releaseId is hardcoded and I wont always know the releaseId but it works for seeding
✅ 1