*Many-to-many*: Use a junction table (<example>) -...
# orm-help
m
Many-to-many: Use a junction table (example) - Seems like this is the solution but the graph.cool sql doesnt follow this format.
j
It basically has to if this was m:n before as well.
k
I think it does follow that but just abstracts it away
m
I had to learn how the tables were working. It was a paradigm shift. I found out how the association tables were working. I missed the table that glues the two models together.
👍 2
I have many Story models that can contain many Video models. The Video models can be a part of many Story models. Not sure if that was needed by design initially but it is what it is. I found there is an association table I was missing that mapped the Story to the Video. Then I learned I needed to update my schema like this
Copy code
t.list.field("stories", {
  type: "story",
  resolve(root: any, args: any, ctx: any) {
    return ctx.prisma["ckcyaq05922nb0193v2fdird7"]
      .findMany({
        where: { user: { id: root.id } }
      })
      .then((d: any) =>
        d.map((e: any) =>
          ctx.prisma.story
            .findOne({
              where: { id: e.b }
            })
            .then((f: any) => f)
        )
      );
  }
});
j
The relation tables are really not pretty in Graphcool.
💯 2
m
Copy code
model ckcyaq05922nc0193n2nyokuv {
  id    String @id
  a     String
  b     String
  story story  @relation(fields: [a], references: [id])
  video video  @relation(fields: [b], references: [id])

  @@index([a], name: "idx_17206_a")
  @@index([b], name: "idx_17206_b")
  @@unique([a, b], name: "idx_17206_ab_unique")
}