https://www.prisma.io/ logo
Join SlackCommunities
Powered by
# orm-help
  • b

    Bård

    06/29/2021, 9:46 AM
    I’m trying to update a relational field:
    Copy code
    prisma.practitioneer.update({
        where: {
          userID,
        },
        data: {
          image: {
            update: {
              where: { id: imageID },
              data: {
                image: image.data,
                type: image.type,
              },
            },
          },
        },
      });
    But I’m getting this error:
    Copy code
    Unknown arg `image` in data.image for type practitioneerUncheckedUpdateInput. Did you mean `imageID`? Available args: …
    If I try to change the query to (which is obviously wrong):
    Copy code
    prisma.practitioneer.update({
        where: {
          userID,
        },
        data: {
          imageID: {
            update: {
              where: { id: imageID },
              data: {
                image: image.data,
                type: image.type,
              },
            },
          },
        },
      });
    I get the same error, only now it’s suggesting the correct field, the one it previously said it didn’t find:
    Copy code
    Unknown arg `imageID` in data.image for type practitioneerUncheckedUpdateInput. Did you mean `image`? Available args: …
    r
    • 2
    • 25
  • u

    user

    06/29/2021, 10:06 AM
    New Course: Fullstack App Using Next.js, GraphQL, TypeScript & Prisma https://www.prisma.io/blog/announcing-upcoming-course-8s41wdqrlgc7 We're thrilled to announce that we're working on a new course where you'll learn how to build a fullstack app using Next.js, GraphQL, TypeScript, and Prisma!
    🎓 2
    👀 3
    typescript 2
    💯 5
    prisma rainbow 5
    nexus 1
    graphql 2
    💥 2
    p
    m
    k
    • 3
    • 3
  • r

    Richard Dunn

    06/29/2021, 11:06 AM
    Hey guys, I'm new to this channel so forgive me if this is the 100th time this question has been asked. Is there any update on the Aurora Data API integration? https://github.com/prisma/prisma/issues/1964
    r
    j
    • 3
    • 6
  • d

    Dev__

    06/29/2021, 1:42 PM
    hello, when I delete a record that has an optional relation to another model, the optional relation's records also get deleted, any way to prevent this?
    Copy code
    model User {
        ....
        memos Memo[]
    }
    
    model Memo {
        userId String?
        user User? @relation(fields: [userId], references: [id])
    }
    j
    r
    • 3
    • 17
  • d

    Dev__

    06/29/2021, 2:58 PM
    on version 2.22 when I tried to delete a record which has a required relation i would get an error with the code
    P2014
    and now on 2.26 I get
    P2003
    . Is this change related to the new update with
    referentialActions
    ?
    m
    j
    • 3
    • 66
  • d

    Dick Fickling

    06/29/2021, 3:51 PM
    foobar1
    ?
    j
    • 2
    • 4
  • p

    Pablo Sáez

    06/29/2021, 5:32 PM
    Hi, version 2.26.0 with pnpm breaks spectacularly, even creates a package-lock.json and tries to overwrite node_modules or something? I created a small repo with the issue with instructions/screenshots in the README https://github.com/PabloSzx/pnpm-prisma-bug and maybe it's important to say that version 2.23.0 everything works fine, every project that uses prisma I have to pin the version to that
    j
    • 2
    • 8
  • m

    Michael Grigoryan

    06/29/2021, 8:36 PM
    Hi, hope you're doing well! I have created a seeder function but it seems like it's not working. Here is the code
    Copy code
    import faker from "faker";
    import { PrismaClient } from "@prisma/client";
    const prisma = new PrismaClient();
    
    export async function seed() {
      const user = await prisma.user.create({
        data: {
          lastName: faker.name.lastName(),
          firstName: faker.name.firstName(),
        },
      });
    
      const post = await prisma.post.create({
        data: {
          userId: user.id,
          body: faker.lorem.slug(300),
        },
      });
    
      console.log({ post, user });
    }
    The information is not being logged and is not being saved to the database... Is there something wrong or am I doing something not correctly?
    j
    m
    • 3
    • 18
  • a

    Awey

    06/29/2021, 10:04 PM
    I have a Post and Comment models. I want to create a Vote model I can use for my Posts/Comments. How would I achieve something like this? I'm having a hard time wrapping my head around it
    r
    • 2
    • 2
  • a

    Antoin Campbell

    06/29/2021, 11:25 PM
    hey all, im having some trouble running a migration script inside of a github action. I am trying to connect to a google cloud sql database with a connection string. (I am able to use the same connection string to connect via GUI and command line, so I know it works), however inside the github action after running
    npx prisma migrate deploy
    I get this error:
    Copy code
    Prisma schema loaded from prisma/schema.prisma
    Datasource "db": PostgreSQL database "postgres", schema "public" at "IP"
    Error: P1001: Can't reach database server at `IP`:`5432`
    
    Please make sure your database server is running at `IP`:`5432`.
    Error: Process completed with exit code 1.
    j
    s
    • 3
    • 11
  • a

    Antoin Campbell

    06/29/2021, 11:28 PM
    anyone ever run into this or have any thoughts on why this might be?
  • p

    prisma chobo

    06/30/2021, 12:45 AM
    Please, Please help me. This is killing my time. this is my model for User:
    Copy code
    model User {
      id                          String                      @id @default(cuid())
      password                    String?                     @db.VarChar(255)
      phoneNumber                 String                      @unique
      createdAt                   DateTime?                   
      updatedAt                   DateTime?                    
      deletedAt                   DateTime?
    }
    and when I do this:
    Copy code
    await prisma.user.create({
            data: {
              password: "password",
              phoneNumber: "+4081824712",
            },
          });
    I get this error:
    Copy code
    Invalid `prisma.user.create()` invocation:
    
    {
      data: {
        createdAt: '2021-06-30T00:41:32Z',
    +   phoneNumber: String,
    ?   id?: String,
    ?   password?: String | null,
    ?   updatedAt?: DateTime | null,
    ?   deletedAt?: DateTime | null
      }
    }
    
    Argument phoneNumber for data.phoneNumber is missing.
    
    Note: Lines with + are required, lines with ? are optional.
    m
    j
    • 3
    • 20
  • p

    prisma chobo

    06/30/2021, 12:45 AM
    I don’t see any problem with my code..
  • p

    prisma chobo

    06/30/2021, 12:46 AM
    is it some kind of bug ?
  • s

    Sean Doughty

    06/30/2021, 4:11 AM
    Is there a clean way to do optional relations in the case where sometimes the relation is linked to one table but other times it is linked to another. For example:
    Copy code
    model Circle {
      id         Int        @id @default(autoincrement())
      name       String
      shape      Shape?
    }
    
    model Square {
      id              Int        @id @default(autoincrement())
      name            String
      shape           Shape?
    }
    
    model Shape {
      id        Int      @id @default(autoincrement())
      type      String
      typeId    Int
      circle    Circle?   @relation(fields: [typeId], references: [id])
      square    Square?   @relation(fields: [typeId], references: [id])
    }
    I think what I am looking for is "optional" relation
    👍 1
    j
    • 2
    • 3
  • a

    Arun Kumar

    06/30/2021, 7:05 AM
    Does
    create
    option in
    upsert
    update if there is an existing record?
    r
    • 2
    • 1
  • a

    Arun Kumar

    06/30/2021, 7:08 AM
    so if we're not sure if the record exists then should we provide the same object to
    create
    and
    update
    r
    • 2
    • 65
  • n

    Nima

    06/30/2021, 7:12 AM
    The new
    referentialActions
    breaks current Studio release 😞 https://github.com/prisma/studio/issues/716
    Copy code
    Error starting Prisma Client: {
      "message": "Schema Parsing P1012\n\nGet config \nerror: The preview feature \"referentialActions\" is not known. Expected one of: microsoftSqlServer, orderByRelation, nApi, selectRelationCount, orderByAggregateGroup, filterJson\n  -->  schema.prisma:9\n   | \n 8 |   provider        = \"prisma-client-js\"\n 9 |   previewFeatures = [\"orderByRelation\", \"nApi\", \"referentialActions\"]\n   | \n\nValidation Error Count: 1\n",
    s
    • 2
    • 1
  • n

    Nima

    06/30/2021, 8:19 AM
    New error this morning on https://cloud.prisma.io/
    j
    d
    s
    • 4
    • 11
  • b

    Bård

    06/30/2021, 8:41 AM
    Hey! I have a question about implementing middleware in a NextJS app. I’m using this approach to include Prisma in the app:
    Copy code
    import { PrismaClient } from '@prisma/client';
    
    // add prisma to the NodeJS global type
    interface CustomNodeJsGlobal extends NodeJS.Global {
      prisma: PrismaClient;
    }
    
    // Prevent multiple instances of Prisma Client in development
    declare const global: CustomNodeJsGlobal;
    
    const prisma = global.prisma || new PrismaClient();
    
    if (process.env.NODE_ENV === 'development') global.prisma = prisma;
    
    export default prisma;
    Is there any best practice way of including a Prisma middleware in a NextJS app? The docs only mentions an express app.
    m
    • 2
    • 2
  • a

    Aman Tiwari

    06/30/2021, 8:51 AM
    hi, I need help with building a matrimonial site, I prefer to choose - language - typescript - frontend - nextjs - backend - prisma 2 + typeGraphql. is it a good choice? any suggestion
    d
    • 2
    • 27
  • a

    aqib

    06/30/2021, 10:34 AM
    Hey! I am getting below error
  • a

    aqib

    06/30/2021, 10:34 AM
    This is my resolvers
    Copy code
    Mutation: {
        ...buildMutationResolvers(prisma.mutation),
      },
      Subscription: {
        submission: {
          subscribe: () =>  pubsub.asyncIterator(['SUBMISSION_CREATED', 'SUBMISSION_UPDATED', 'SUBMISSION_DELETED'])
        },
        submissionReview: {
          subscribe: () => pubsub.asyncIterator(['WAR_CREATED', 'WAR_UPDATED', 'WAR_DELETED'])
        }
      },
  • a

    aqib

    06/30/2021, 10:35 AM
    This is how I am building the mutation resolvers
    Copy code
    const buildMutationResolvers = (methods) =>
      Object.entries(methods).reduce(
        (resolvers, [queryName, queryFunc]) => ({
          ...resolvers,
          [queryName]: async (parent, args, context, info) => {
            const label = getPublishLabel(queryName)
            // const data = await queryFunc(args, info)
            if(label) {
              pubsub.publish(label[0], { [label[1]]: args});
            }
            return queryFunc(args, info)
          },
        }),
        {}
      );
  • a

    aqib

    06/30/2021, 10:36 AM
    method to get the label
    Copy code
    const getPublishLabel = (mutationName) => {
      const labels = {
        createSubmission: ['SUBMISSION_CREATED', 'submission'],
        updateSubmission: ['SUBMISSION_UPDATED', 'submission'],
        deleteSubmission: ['SUBMISSION_DELETED', 'submission'],
      }
    
      if(!!labels[mutationName]) return labels[mutationName]
      return false
    }
    r
    • 2
    • 2
  • a

    aqib

    06/30/2021, 10:36 AM
    What am I doing wrong ?
  • e

    Edmir Suljic

    06/30/2021, 10:42 AM
    how can I get a record from the db by providing an enum argument instead of id? It is the id that I want to figure out and I want the client to provide an enum instead. Im thinking something like this:
    Copy code
    const device = await prisma.device.findUnique({
          where: {
            deviceType: {
              contains: args.data.deviceType
            }
          },
          connect: {
            user: {
              id: userId
            }
          }
        });
    This obviously doesnt work but hopefully you would get the idea.
    r
    • 2
    • 6
  • n

    Nimish Gupta

    06/30/2021, 11:27 AM
    Hello prisma team, I have a doubt with respect to raw queries. So I have the below model (Using
    Postgres
    as DB)
    Copy code
    model Test {
      id String @id @default(uuid())
    
      name           String
    
      // common fields
      createdAt DateTime @default(now()) @map("created_at")
      updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
    
      @@map("test")
    }
    and using below code snippet in node js.
    Copy code
    async function update() {
          // Node js
          // Current state of the row in the DB
          await model.test.findUnique({ where: { id: 1 } });
          // { id: 1, name: "current_value", updated_at: "2021-06-30T11:00:16.291Z", created_at: "2021-06-30T11:00:16.291Z"}
          await model.test.updateMany({ data: { name: "after_update" } });
          // { id: 1, name: "after_update", updated_at: "2021-06-30T12:00:16.291Z", created_at: "2021-06-30T11:00:16.291Z"}
          await model.$queryRaw(`UPDATE test set name = 'updater_after_raw'`); // @rawQuery
          // { id: 1, name: "updater_after_raw", updated_at: "2021-06-30T12:00:16.291Z", created_at: "2021-06-30T11:00:16.291Z"}
        }
    Here after
    @rawQuery
    ,
    update_at
    field is not being updated. Couldn't understand this behaviour. Is this intentional or any issue? Expected behaviour - It should update the
    updated_at
    field when I am writing raw update query in prisma.
    r
    • 2
    • 6
  • s

    stephan levi

    06/30/2021, 12:06 PM
    Hi, Is there a way to filter by a string type field, with contains_every ?
    r
    • 2
    • 15
  • b

    Bård

    06/30/2021, 12:46 PM
    Any way to update a field on connect? Seems like the problem is I can’t update a relational field inside a create.
    Copy code
    prisma.user.create({
      someRelationalField: {
        connect: {
          userId: userID
        },
        update: {
           // Is this possible?
        }
      }
    })
1...451452453...637Latest