prisma / studio

🎙️ The easiest way to explore and manipulate your data in all of your Prisma projects.
https://www.prisma.io/studio
1.87k stars 48 forks source link

Semi invalid MongoDB relation are shown semi weird #897

Open janpio opened 2 years ago

janpio commented 2 years ago

I have this MongoDB schema:

generator client {
  provider        = "prisma-client-js"
  previewFeatures = "mongodb"
}

datasource db {
  provider = "mongodb"
  url      = "..."
}

model Foo {
  id          String    @id @default(auto()) @map("_id") @db.ObjectId
  name        String    @unique
  telephone   Telephone @relation(fields: [telephoneId], references: [id])
  telephoneId String    @db.ObjectId
}

model Telephone {
  id   String @id @default(auto()) @map("_id") @db.ObjectId
  foos Foo[]
}

and this data:

Foo:

[{
  "_id": {
    "$oid": "624455a20e4ea7cdaa8950ee"
  },
  "name": "Foo",
  "telephoneId": "624462600e4ea7cdaa8950f3"
}]

Telephone:

[{
  "_id": {
    "$oid": "624462600e4ea7cdaa8950f3"
  }
}]

When I open Foo it shows and entry, that it shows as connected to 1 item. Clicking on it, shows the Telephone entry. When I open Telephone it shows the entry as well - but with 0 items in the foos relation. When I open the relation anyway and then open that in a new tab with the link for that, it returns 0 results.

I think the solution is that the underlying data is invalid. Foo should actually be:

[{
  "_id": {
    "$oid": "624455a20e4ea7cdaa8950ee"
  },
  "name": "Foo",
  "telephoneId": {
    "$oid": "624462600e4ea7cdaa8950f3"
  }
}]

Note how the value of telephoneId is different.

janpio commented 2 years ago

(Might also just be a Prisma Client problem) Update: Now an issue at https://github.com/prisma/prisma/issues/12608