How do I configure schema model for many-many rela...
# orm-help
z
How do I configure schema model for many-many relationship?
n
Copy code
type A {
  id: ID! @unique
  as: [B!]!
}
type B {
  id: ID! @unique
  bs: [A!]!
}
Does something like this work for you?
z
Sure does! In respect to Prisma though... 'deploy prisma' complains about not specifying link relation directive on 1 side...
Copy code
type A {
  id: ID! @unique
  as: [B!]! @relation(link: INLINE)
}
type B {
  id: ID! @unique
  bs: [A!]!
}
So i just want to confirm that Prisma will handle cascading updates on both sides of the many-many relationship? Therefore, does it matter which side I put the directive on?
as: [B!]! @relation(link: INLINE)
OR
bs: [A!]! @relation(link: INLINE)
n
looks like you're using datamodel v2 with mongodb...
i don't think inline relations can be many-to-many
z
when i remove
@relation(link: INLINE)
i get these errors when trying to deploy. But like you said, it sounds like a datamodel v2 issue. So is there no way to handle many-many relationships in v2? A ✖️ The field
B
must provide a relation link mode. Either specify it on this field or the opposite field. Valid values are:
@relation(link: INLINE)
B ✖️ The field
A
must provide a relation link mode. Either specify it on this field or the opposite field. Valid values are:
@relation(link: INLINE)
n
Try:
Copy code
type A {
 id: ID! @unique
 as: [B!]! @relation(name: "some_relation")
}
type B {
 id: ID! @unique
 bs: [A!]! @relation(name: "some_relation")
}
z
Copy code
type Message {
  id: ID! @id
  comments: [messageComment!]! @relation(name: "CommentMessages")
  createdDate: DateTime @createdAt
}
type messageComment {
  id: ID! @id
  messages: [Message!]! @relation(name: "CommentMessages")
  createdDate: DateTime @createdAt
}
produced this error
messageComment ✖️ You are trying to set the relation 'CommentMessages' from
messageComment
to
Message
and are only providing a relation directive with a name on
messageComment
. Plea se also provide the same named relation directive on the relation field on
Message
pointing towards
messageComment
.
n
Weird... you're doing just that...
z
hmmmm thanks for your help... im still trying... ill update once I figure it out
the issue was that I was changing the cardinality, so theres a certain way handle that... Therefore it should work on the first go-round