Skip to content
This repository has been archived by the owner on Jan 14, 2021. It is now read-only.

Nested writes don't work on 3rd level with required relation #275

Closed
nikolasburk opened this issue Oct 28, 2019 · 8 comments
Closed

Nested writes don't work on 3rd level with required relation #275

nikolasburk opened this issue Oct 28, 2019 · 8 comments
Assignees
Labels
bug/2-confirmed We have confirmed that this is a bug. kind/bug A reported bug.
Milestone

Comments

@nikolasburk
Copy link
Member

I have these models:

model Item {
  id           String   @default(cuid()) @id
  createdAt    DateTime @default(now())
  updatedAt    DateTime @updatedAt
  purchaseDate DateTime?
  name         String
  type         ItemType
  locatedIn    Room?
  price        Float?
}

model ItemType {
  id    String @default(cuid()) @id
  name  String @unique
  items Item[]
}

model Room {
  id          String  @default(cuid()) @id
  name        String  @unique
  items       Item[]
  floor       Floor?
  meetingRoom Boolean
}

I now want to create a new Room with new Items which all need an ItemType. However, the nested write arguments are not available for the type field on created Items:

photon.rooms.create({
  data: {
    items: {
      create: {
        type: {  // ... not available
                 // create/connect ... not available
        }
      }
    }
  }
})

image

image

@pantharshit00 pantharshit00 added bug/2-confirmed We have confirmed that this is a bug. kind/bug A reported bug. labels Oct 31, 2019
@pantharshit00
Copy link
Contributor

I can confirm this.

Here is a reproduction for internal use: https://github.com/harshit-test-org/prisma-photonjs-275

@ManAnRuck

This comment has been minimized.

@pantharshit00

This comment has been minimized.

@divyenduz divyenduz added the process/candidate Candidate for next Milestone. label Dec 9, 2019
@divyenduz

This comment has been minimized.

@divyenduz divyenduz modified the milestones: Preview 24 Old, Preview 25 Mar 13, 2020
@dpetrick
Copy link

This is not reproducible on the engine level, I can write a GraphQL mutation directly against the query engine that allows for creating item types.

@dpetrick
Copy link

To elaborate:

  • Needed to remove floor Floor? that snuck in :)
  • This query works in the query engine:
mutation {
  createOneRoom(data:{
    name: "SomeRoom"
    meetingRoom: true
    items: {
      create:{
        name: "SomeItem"
        type:{
          create:{
            name: "SomeType"
          }
        }
      }
    }
  }) {
    id
  }
}

@janpio
Copy link
Member

janpio commented Mar 16, 2020

I adapted the reproduction above to alpha 917:

  1. prisma2 init
  2. Edit datasource.provider to sqlite, datasource.url to "file:dev.db"
  3. Append schema:
    model Item {
      id           String   @default(cuid()) @id
      createdAt    DateTime @default(now())
      updatedAt    DateTime @updatedAt
      purchaseDate DateTime?
      name         String
      type         ItemType
      locatedIn    Room?
      price        Float?
    }
    
    model ItemType {
      id    String @default(cuid()) @id
      name  String @unique
      items Item[]
    }
    
    model Room {
      id          String  @default(cuid()) @id
      name        String  @unique
      items       Item[]
      meetingRoom Boolean
    }
  4. prisma2 migrate save --experimental and prisma2 migrate up --experimental
  5. Create index.js with content:
    const { PrismaClient } = require('@prisma/client')
    
    const prisma = new PrismaClient()
    
    prisma.Room.create({
        data: {
            items: {
                create: {
                    
                }
            }
        }
    })

This leads to these suggestions:

image

Is this the expected behavior @nikolasburk and this bug can be closed?

@janpio janpio assigned janpio and unassigned mavilein Mar 16, 2020
@nikolasburk
Copy link
Member Author

Looks good to me, thanks a lot 🙏

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug/2-confirmed We have confirmed that this is a bug. kind/bug A reported bug.
Projects
None yet
Development

No branches or pull requests

7 participants