生成棱镜时的模糊关系

时间:2019-07-05 08:55:02

标签: sql relational-database prisma

我无法使用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模型,我一直在尝试分别创建marketsbase之间的关系。我认为没有必要包括其他模型。

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.marketsExchangeMarket[],其中ExchangeMarket.baseCoin。并使其生成也没有错误。

任何帮助将不胜感激。

修改 我在重复的帖子中尝试了建议的更改,但没有成功。调用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[]
}

0 个答案:

没有答案