I'm trying to deploy this many to many relationship according to the docs:
type ShortCodeTx {
id: ID! @id
jars: [Jar!]! @relation(link: TABLE, name: "ShortCodeTxJars")
}
type ShortCodeTxJars @relationTable {
jar: Jar!
shortCodeTx: ShortCodeTx!
}
type Jar {
id: ID! @id
transactions: [ShortCodeTx!]!
}
but I'm getting this error which seems to go against what the docs say:
ShortCodeTx
✖ You are trying to set the relation 'ShortCodeTxJars' from `ShortCodeTx` to `Jar`
and are only providing a relation directive with a name on `ShortCodeTx`.
Please also provide the same named relation directive on the relation field on `Jar`
pointing towards `ShortCodeTx`.
In any case, I updated Jar with a relation directive type as it says in the error:
type Jar {
id: ID! @id
transactions: [ShortCodeTx!]! @relation(link: TABLE, name: "ShortCodeTxJars")
}
However it just comes back with this error which tells me to switch back:
✖ The `link` argument must be specified only on one side of a relation. The field
`jars` provides a link mode and the opposite field `transactions` as well.}
Jar
✖ The `link` argument must be specified only on one side of a relation. The field
`transactions` provides a link mode and the opposite field `jars` as well.}
@captDaylight
Use the following datamodel:
type ShortCodeTx {
id: ID! @id
jars: [Jar!]! @relation(link: TABLE, name: "ShortCodeTxJars")
}
type ShortCodeTxJars @relationTable {
jar: Jar!
shortCodeTx: ShortCodeTx!
}
type Jar {
id: ID! @id
transactions: [ShortCodeTx!]! @relation(name: "ShortCodeTxJars")
}
You don't need to define to link in both the ends, our internal logic counts it as a new relationship and will cause the above error.
@pantharshit00 thanks for the explainer above. However, when I open up my prisma dashboard, I'm seeing transactions field on the Jar type but I'm not seeing the equivalent field jars on the ShortCodeTx type.
@captDaylight
Please verify the details in the playground first. Sometimes you see the cached datamodel in the playground. Try clearing your browser's localStorage to reset it
Most helpful comment
@captDaylight
Use the following datamodel:
You don't need to define to link in both the ends, our internal logic counts it as a new relationship and will cause the above error.