我无法使用Prisma在两个模型之间的两个字段上建立M:N关系。当我致电prisma2 generate
时发生错误。我知道Prisma2当前处于预览状态,但是我确定这只是我对如何使用@relation
属性的误解。
我在字段上尝试了@relation
属性的多种变体:
@relation("Relation Name")
@relation("oppositeField")
@relation(["oppositeField"])
@relation("oppositeField", name: "Relation Name")
@relation(["oppositeField"], name: "Relation Name")
@relation(["firstField", "linkedField"], name: "Relation Name")
如果您不知道@relation
的工作原理,那么尽管没有十分清楚,但还是有一些documentation。
我还尝试向qmarkets ExchangeMarket[]
添加一个Coin
字段,因为Prisma似乎需要ExchangeMarket.quote
的双向关系,但无济于事。
基本上,这是两个Prisma模型,我一直在尝试分别创建markets
和base
之间的关系。我认为没有必要包括其他模型。
model Coin {
id String @id @unique @default(cuid())
symbol String
name String @unique
description String
platform Coin?
max Float?
markets ExchangeMarket[]
aggregates AggregateTick[]
}
model ExchangeMarket {
id String @id @unique @default(cuid())
exchange Exchange
base Coin
quote Coin
data MarketTick[]
}
我主要收到的错误是Did not find a relation for those for model ExchangeMarket and field quote
。
我希望Coin.markets
是ExchangeMarket[]
,其中ExchangeMarket.base
是Coin
。并使其生成也没有错误。
任何帮助将不胜感激。
修改
我在重复的帖子中尝试了建议的更改,但没有成功。调用prisma2 generate
时显示相同的错误。现在的模型如下所示:
model Coin {
id String @id @unique @default(cuid())
symbol String
name String @unique
logo String?
description String
platform Coin?
max Float?
markets ExchangeMarket[] @relation(name: "CoinMarkets")
qmarkets ExchangeMarket[] @relation(name: "CoinQuoteMarkets")
aggregates AggregateTick[]
}
model ExchangeMarket {
id String @id @unique @default(cuid())
exchange Exchange
base Coin @relation(name: "CoinMarkets")
quote Coin @relation(name: "CoinQuoteMarkets")
ticks MarketTick[]
}