Jay Cammarano
06/13/2021, 3:45 PMReleases 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:
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:
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.Jay Cammarano
06/13/2021, 4:03 PMSELECT * FROM "ArtistsOnReleases"; returns (0 rows)Jay Cammarano
06/13/2021, 5:30 PMconst 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