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

    Josef Henryson

    10/05/2022, 12:21 PM
    Hi there. Do you know how Prisma client handles a restart of the database (MySQL in my case)? We have a situation where Prisma runs on the same server as MySQL. After a windows update it happens that Prisma starts up before MySQL and then throws an error. This requires a manual restart of the node server when DB is up and running. We are thinking of moving MySQL to a different server to solve this problem for future updates/restart. But will the problem remain if the DB server reboots?
    ✅ 1
    n
    • 2
    • 5
  • d

    Dibas Dauliya

    10/05/2022, 12:50 PM
    hello, I want to create the comments table. It has
    post
    column with relation to
    postID
    . I gave
    postID
    and assumed it will automatically fill
    post
    but I gave me error asking for
    post
    . How can I include post in it?
    ✅ 1
    n
    • 2
    • 8
  • e

    Evangelos Charalampidis

    10/05/2022, 1:02 PM
    Hi, I am working on relations with prisma and cannot figure out how to link a new entry to a table. That’s my schema
    model User {
    id        Int       @id @default(autoincrement())
    createdAt DateTime  @default(now())
    updatedAt DateTime  @updatedAt
    username  String?
    age       Int?
    bio       String?
    location  String?
    tasks     Task[]
    comments  Comment[]
    }
    model Task {
    id          Int            @id @default(autoincrement())
    createdAt   DateTime       @default(now())
    updatedAt   DateTime       @updatedAt
    title       String?
    description String?
    progress    ProgressStatus @default(ToDo)
    taskType    TaskType       @default(Personal)
    comments    Comment[]
    User        User?          @relation(fields: [userId], references: [id])
    userId      Int?
    }
    enum ProgressStatus {
    ToDo
    InProgress
    Blocked
    Completed
    }
    enum TaskType {
    Personal
    Coding
    Bruno
    House
    }
    model Comment {
    id        Int      @id @default(autoincrement())
    createdAt DateTime @default(now())
    updatedAt DateTime @updatedAt
    desc      String
    likes     Int?
    dislikes  Int?
    Task      Task?    @relation(fields: [taskId], references: [id])
    taskId    Int?
    User      User?    @relation(fields: [userId], references: [id])
    userId    Int?
    }
    that’s how I create three users
    const users = await prisma.user.createMany({
    data: [
    {
    username: "imevanc",
    age: 25,
    bio: "I love maths",
    location: "Earth",
    },
    {
    username: "imevancc",
    age: 30,
    bio: "I love physics",
    location: "Mars",
    },
    {
    username: "imevanc",
    age: 35,
    bio: "I love biology",
    location: "Jupiter",
    },
    ],
    });
    and here I’m trying to associate the first task that I create with the first user. however, both tasks are linked to the first user for some reason.
    const task = await prisma.task.createMany({
    data: [
    {
    title: "Bruno's morning walk",
    description:
    "I need to take Bruno to the park and walk him for just over an hour.",
    progress: "Completed",
    taskType: "Bruno",
    userId: 1,
    },
    {
    title: "Bruno's evening walk",
    description: "I need to walk Bruno in the city center.",
    progress: "ToDo",
    taskType: "Bruno",
    },
    ],
    Any help would be appreciated! Cheers!
    });
    ✅ 1
    n
    • 2
    • 2
  • m

    Marvin

    10/05/2022, 2:19 PM
    Hey everyone! I'm trying to create a one-to-many self-relation with an extra relation table between where I can store additional information. Somehow the relations always error. Is this even possible? My code looks something like this
    Copy code
    model User {
      id String @id @default(cuid())
      
      friends FriendOnUser[]
    }
    
    model FriendOnUser {
      id String @id @default(cuid())
    
      addedAt DateTime @default(now())
    
      parentId String?
      parent User @relation(name: "ParentUser", fields: [parentId], references: [id])
    
      friendId String?
      friend User @relation(name: "FriendUser", fields: [parentId], references: [id])
    }
    👀 1
    r
    v
    • 3
    • 6
  • f

    Florian

    10/05/2022, 2:42 PM
    Hi 🙂 I was wondering if there was any advantage when using
    Copy code
    prisma.modelOne.create({
      data: {
        id: '1',
        field: 'string',
        modelTwo: {
          connect: {
            id: someID,
          },
        },
      },
    });
    over
    Copy code
    prisma.modelOne.create({
      data: {
        id: '1',
        field: 'string',
        modelTwoID: someID,
      },
    });
    or if both methods are the same?
    schema.prisma
    would look something like this:
    Copy code
    model ModelOne {
      id    String @id
      field String
    
      modelTwo   ModelTwo  @relation(name: "ModelsRelation", fields: [modelTwoID], references: [id], onDelete: Cascade)
      modelTwoID String
    }
    
    model ModelTwo {
      id    String @id
      field String
    
      modelOnes ModelOne[] @relation(name: "ModelsRelation")
    }
    ✅ 1
    r
    • 2
    • 4
  • j

    Joey

    10/05/2022, 2:45 PM
    Ok it looks like it’s
    ModelNameUpdateInput
    , but I can’t figure out how to import that, anyone know?
    n
    • 2
    • 3
  • v

    Vivek Poddar

    10/05/2022, 3:49 PM
    Hi Team, I am planning to have audit in some of the models by adding fields like
    createdAt
    ,
    updatedAt
    ,
    createdBy
    ,
    updatedBy
    fields, but I am getting issues when I there is already an existing relationship with
    User
    . For example
    Copy code
    model Order {
      user User @relation(fields: [userId], references: [id], onDelete: Cascade, onUpdate: Cascade)
      ...
      createdBy User?  
    }
    I get the following error:
    Copy code
    Error validating model "Partner": Ambiguous relation detected. The fields `user` and `createdBy` in model `Partner` both refer to `User`. Please provide different relation names for them by adding `@relation(<name>).
    1. How can I resolves this issue? 2. Is there any better pattern?
    👀 2
    👍 1
    ✅ 1
    🙏 1
    r
    v
    • 3
    • 4
  • p

    Peter

    10/05/2022, 6:28 PM
    Do we need to run
    prisma generate
    in production?
    ✅ 1
    j
    r
    a
    • 4
    • 6
  • j

    John Allen Delos Reyes

    10/06/2022, 3:29 AM
    Hi, I'm having an error when creating an asset. `Unknown arg
    type
    in data.type for type assetUncheckedCreateInput. Did you mean
    typeId
    ? Available args: type assetUncheckedCreateInput`
    ✅ 1
    j
    • 2
    • 19
  • y

    Yunbo

    10/06/2022, 3:38 AM
    $queryRaw
    nested object. is there any way i can get nested object from
    $queryRaw
    for example,
    Copy code
    prismaClient.$queryRaw`
        SELECT 
            users.id, users.name, 
            user_statuses.id AS "userStatus[id]",
            user_statuses.name AS "userStatus[name]"
          FROM users
            INNER JOIN user_statuses ON user_statuses.id = user.status_id
          WHERE users.id = ${userId}
    `
    expected result
    Copy code
    [
      {
        id: 1,
        name: "test user",
        userStatus: {
          id: 1,
          name: "verified"
        } 
      }
    ]
    NOTE: I explicitly want to use
    $queryRaw
    ✅ 1
    n
    • 2
    • 2
  • d

    Daniele

    10/06/2022, 8:20 AM
    Hello guys i have a problem with transaction in Prisma. Shortly, i need to perform 3 queries with the 2° and 3° query depend on the result of the first query. The 2° and the 3° queries can be done with one transaction, but if this transaction fail i need to rollbaack the first one. Is there any way i can do this with prisma? Thank you!
    👀 1
    ✅ 1
    j
    n
    • 3
    • 6
  • t

    Taylor Lindores-Reeves

    10/06/2022, 9:56 AM
    Hi guys, this may not be Prisma related necessarily but I was wondering what the best practice is for storing DateTime? At the moment, our PG database is storing the UTC timestamp which is 1 hour behind my local time. It’s quite frustrating and as we’re building a start-up with serious investment, we want to be sure we’re adhering to best practices. Any suggestions?
    💬 1
    n
    • 2
    • 1
  • s

    Slackbot

    10/06/2022, 11:35 AM
    This message was deleted.
    n
    e
    • 3
    • 2
  • q

    Quentin Laffont

    10/06/2022, 12:37 PM
    Hello Hello 👋, We are currently switching from TypeORM to Prisma. And we have a missing feature and I want to know if this feature is planned or already done in another project. • Migrations in Typescript ? • Able to easely execute up and down migrations ? • Able to add custom migrations script before and after migrations (Example: migrate data to another table when SQL migrations script is executed) Thanks ^^
    ✅ 1
    n
    • 2
    • 8
  • k

    Kyle Gammon

    10/06/2022, 1:14 PM
    I don't suppose anyone has any further insight into a question I posted previously? (https://prisma.slack.com/archives/CA491RJH0/p1663142888270189) The TLDR is I want to write a query which will find entries where a certain relationship field is empty (e.g. if a Post model had a relationship field to a Tag model, I want to get Posts which have no Tags). Ideally I want to do this through a GraphQL query rather than purely at resolver level. Any thoughts would be most appreciated!
    ✅ 1
    n
    • 2
    • 5
  • z

    Zakaria Mofaddel

    10/06/2022, 2:06 PM
    Is anybody having issues with Nexus after updating to prisma V4? I keep getting an error that looks like this:
    Copy code
    Error: NEXUS__UNKNOWN__TYPE was already defined and imported as a type, check the docs for extending types
    👀 1
    n
    r
    • 3
    • 4
  • p

    Pat

    10/06/2022, 2:19 PM
    Hello Prisma People! qq on migrations`*`: Anne creates a feature branch with a migration. Ben creates a separate feature branch, with a different migration at a later date, but merges his code before Anne does. Should Anne attempt to rename her migration file so that it is ordered after Ben's? It's likely not an issue until Claire is added to the team and wants to run all migrations... unless Anne renames, Claire will run the migrations in a different order than other environments. ---
    *
    - I'm sure has been answered many times before, but I'm having a hard time googling for the answer!
    ✅ 1
    n
    v
    • 3
    • 4
  • b

    Balázs Szalay

    10/06/2022, 2:30 PM
    Hey, I was just wondering if there is any way to create virtual generated columns for postgresql using prisma? Cheers, Balázs
    👀 2
    n
    • 2
    • 3
  • b

    Ben Guthrie

    10/06/2022, 3:48 PM
    👋 Hello! Has anyone found a way to do case insensitive filtering on a property of a JSON column? I've seen this issue that others are wanting a similar functionality.
    ✅ 1
    a
    • 2
    • 1
  • b

    Bryon Mapes

    10/06/2022, 3:56 PM
    Using a single prisma.$transaction is it possible to update the same value with two different values, even if both are awaited? My transaction times out, and I am having trouble finding the correct term to look up why. I realize I don't need to do that anymore, however I will need to know why. Thank you
    Copy code
    Transaction
    await update value A to 2
    await update value A to 2
    End Transaction
    👀 1
    ✅ 1
    a
    • 2
    • 4
  • t

    Ty-Lucas Kelley

    10/06/2022, 3:58 PM
    Hey all! I find myself perpetually going back to this GitHub discussion about
    hashids
    and Prisma - https://github.com/prisma/prisma/discussions/10588 We're finding that our adoption to Prisma is resulting in far more boilerplate than we want, for two reasons: 1. Lack of support for generics 2. Lack of support for something like TypeORM's
    transformer
    argument to a column definition Our desire is to be able to have a model that looks like this:
    Copy code
    model Foo {
      id  Int  @id @default(autoincrement())
    }
    But be able to use
    hashids
    so that the IDs are represented as encoded strings for any client code, so we could do this:
    Copy code
    const foo = await prisma.foo.findUnique({ where: { id: "some string" })
    And
    some string
    would be decoded to the underlying database ID. We haven't figured out a middleware solution for doing this, resulting in a lot of extra effort spent calling
    encodeId
    and
    decodeId
    all over the place whenever we're passing primary/foreign keys from the client to the server. Anyone have solid ideas or examples for how to do this efficiently? Not ruling out a middleware solution, just haven't found a good way to do it
    👀 1
    r
    a
    • 3
    • 7
  • m

    Matheus Assis

    10/06/2022, 8:05 PM
    We’re removing
    nexus-plugin-prisma
    from our project following the guide: https://nexusjs.org/docs/plugins/prisma/removing-the-nexus-plugin-prisma#migrating-from-tcrud-to-plain-nexus The issue is that it’s messing up
    null
    and
    undefined
    types We converted the types using the SDL converter, but when we provide the
    args
    variable to prisma, it complains of nullability because graphql returns those as null but prisma don’t expect them to be null. Even when following the “Pagination, filtering, sorting” section on the guide. The guide just does a
    cursor: args.cursor || undefined
    . But that seems to be wrong, instead, we’d have to manually destructure the `cursor`(like done with the
    where
    ). The issue is that the
    where
    could be anything, the
    orderby
    could be anything, and until how many nested values should we destructure? Is there a better way of handling this? How one should do it? Is the doc outdated? Also, we saw this https://github.com/graphql-nexus/nexus-plugin-prisma/blob/main/src/null.ts. Would that be the recommended approach? cc: @Adarley Grando
    👍 1
    👀 1
    n
    a
    • 3
    • 3
  • t

    Ted Joe

    10/06/2022, 9:29 PM
    How can I make multiple 1 to 1 relationships with the same models?
    👀 1
    r
    v
    • 3
    • 2
  • a

    AJ Holloway

    10/06/2022, 9:31 PM
    If I’m doing a create on a table that has an auto-incrementing ID (postgres), is there a Prisma generated type I can use that allows the id parameter to be optional? I don’t want to include an id in my request so that the DB can auto create it’s ID.
    ✅ 1
    r
    • 2
    • 2
  • л

    Леонид Шабалкин

    10/07/2022, 6:45 AM
    Hello, I started using filteredRelationCount, is it possible to apply a filter to the sort used by _count?
    👀 1
    ✅ 1
    n
    • 2
    • 6
  • r

    Richard Scarrott

    10/07/2022, 10:33 AM
    This is perhaps a niche issue, but I wonder if anybody knows a workaround for this:
    Copy code
    console.log(prisma.user.findUnique === prisma.user.findUnique); // EXPECT: true, ACTUAL: false
    I think it's caused by the use of getters or maybe
    Proxy
    ?
    ✅ 1
    n
    • 2
    • 8
  • o

    Oliver St.

    10/07/2022, 12:18 PM
    What is the default
    connection_limit
    of prisma if you don’t specify one in the
    DATABASE_URL
    ?
    n
    • 2
    • 3
  • m

    Matt

    10/07/2022, 1:42 PM
    I’m having an issue with a implicit self referential relation on a model. Based on the docs, I believe I should be able to write this
    Copy code
    model Area {
      id         String   @id @default(cuid())
      name       String
      type       AreaType
      code       String
      intersects Area[]   @relation("AreaIntersects")
    }
    Where
    intersects
    is self-referencing the model, but the VSCode plugin keeps trying to correct it by adding additional rules (which it also doesn’t seem to like)
    ✅ 1
    n
    • 2
    • 8
  • j

    Joey

    10/07/2022, 2:41 PM
    Is there any way to fetch a list of relations without any joins, but then for one specific id, include joins? Obviously I can do this in two queries, but was curious if there’s a supported way to do it in one? something like:
    Copy code
    const user = await db.user.findFirst({
        where: { id: user.id },
        include: {
          blogs: true,
          <specific blog with relations>: { where: { id }, include { ... } }
        }
      });
    ✅ 1
    a
    • 2
    • 2
  • j

    Jonathan Marbutt

    10/07/2022, 2:48 PM
    I am trying to remember how to read the schema in code, I feel like there was a way but I can’t find it in the docs. I know I have done it before. I just want to loop over my models and their properties
1...629630631...637Latest