Hi hi, are all many-to-many relations in prisma di...
# orm-help
n
Hi hi, are all many-to-many relations in prisma directed?
e.g. I have a type called
Content
, which can be attached to other
Content
. So, in my data model:
Copy code
type Content {
  attachments: [Content!]! @relation(name: "AttachedContent")
}
if I connect two Content records, it shows up properly in my db (and I can query that the second is attached to the first, but if I query the second record it doesn’t show the first in its
attachments
I assume that’s expected, but I can’t find any docs / best practices around doing undirected self-referential (many-to-many) relations with the same property
(should I instead have two properties (
attachments
and
attachedTo
, and then merge them together at the api layer?)
if anyone's searching for this extremely niche issue in the future, I ended up going with two properties:
attachedTo
and
attachedFrom
. I'm serving them in my api, as well as an (api only)
attachments
field that combines both. My clients that need to edit attachments will have to use the individual fields (which isn't too onerous), while my read-only clients can look at the combined field