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

    glekner

    08/04/2021, 10:13 PM
    hey all, i’m, having a many to many relationship between
    Branches
    and
    Labels
    i’m trying to write a mutation to add a branch to a label.
    Copy code
    t.field('addBranchToLabel', {
          type: 'Label',
          args: {
            data: nonNull(
              arg({
                type: 'LabelAddBranchCreateInput',
              }),
            ),
          },
          resolve: async (_parent, { data }, ctx) => {
            const branch = await ctx.prisma.branch.findUnique({
              where: {
                id: data.branchId,
              },
            })
            if (!branch) {
              throw new Error('Invalid Branch')
            }
            const label = await ctx.prisma.label.findUnique({
              where: {
                name: data.labelName,
              },
            })
            if (!label) {
              throw new Error('Invalid Label')
            }
    
            console.log('label', label)
    
            return ctx.prisma.label.update({
              where: { name: label.name },
              data: {
                branches: {
                  connectOrCreate: [
                    {
                      where: {
                        id: data.branchId,
                      },
                      create: branch,
                    },
                  ],
                },
              },
            })
          },
        })
    the mutation works, but when I query the branches list of the label, it returns
    null
    , so the branch wasnt added. any help? here is the model
    Copy code
    model Label {
      id        String    @id @default(cuid())
      name      String    @unique
      branches  Branch[]
      createdAt DateTime? @default(now())
    }
  • i

    Ivan Jeremic

    08/04/2021, 10:20 PM
    Is prisma studio open-source? I can't find the source code on github.
    r
    • 2
    • 2
  • g

    glekner

    08/04/2021, 10:38 PM
    https://prisma.slack.com/archives/CA491RJH0/p1628115202140400
    I do see the branches in Prisma studio
  • g

    glekner

    08/04/2021, 10:39 PM
    but when I query the branches from the label, it returns null.. ?
  • g

    glekner

    08/04/2021, 10:39 PM
  • g

    glekner

    08/04/2021, 10:56 PM
    solved it, needed to add
    context.prisma.label.findMany({ include: { branches: true } })
    💯 1
  • o

    Oluwasetemi Ojo

    08/05/2021, 8:30 AM
    Does anyone know how to convert JSON schema to swagger definitions for swagger documentation
  • d

    David

    08/05/2021, 11:32 AM
    hi guys, do anyone experienced the
    runtime
    folder went missing in prisma folder inside node_modules?
  • d

    David

    08/05/2021, 11:32 AM
    I got this error because of that:
    Copy code
    const dirname = findSync(process.cwd(), [
                    ^
    TypeError: findSync is not a function
  • d

    David

    08/05/2021, 11:33 AM
    when i look into the directory declared in error output:
    Copy code
    node_modules/.prisma/client/index.js:55
    I found it like this, but the runtime folder isn't exist.
  • d

    David

    08/05/2021, 11:36 AM
    oh wait, its inside
    @prisma
    , the runtime folder is exist, but not the
    findSync
    r
    j
    • 3
    • 26
  • u

    user

    08/05/2021, 5:02 PM
    What is Semantic Versioning and why you should know about it - by Mahmoud Abdelwahab

    https://www.youtube.com/watch?v=5NQUut8uf9w▾

    If you're a developer, you have to know what Semantic Versioning (SemVer) is. Learn about it in this video by Prisma DevRel Advocate Mahmoud Abdelwahab 🚀 In short: by adopting SemVer, you make it easier for users to understand which version may contain breaking changes. It's also easier for developers to know which minor versions contain opt-in Preview and Early Access features that are not active by default. Overall, this is an industry best practice and improves the developer experience. ‣ Prisma SemVer full blog post: https://www.prisma.io/blog/prisma-adopts-semver-strictly ‣ Prisma releases and maturity levels: https://www.prisma.io/docs/about/releases ‣ SemVer best practices deep dive: https://semver.org/ ‣ Full list of current Prisma releases: https://github.com/prisma/prisma/releases Learn more about Prisma: ◭ Website: https://www.prisma.io​​​ ◭ Docs: https://www.prisma.io/docs​​​ ◭ Quickstart: https://www.prisma.io/docs/getting-started/quickstart-typescript
  • d

    Daniel Olavio Ferreira

    08/05/2021, 8:17 PM
    Hello everyone, does anyone know if there is anyway to make a model with a relation included in the query by default. The use case is: I have a table of comments, where each comment is can have a parent comment and children comments. I want to query only the parents, and that the children be included for every single one, not only the top level ones. Right now I implemented it with a simple algorithm, but it would be great if prisma had support for something like such. Here is the algorithm:
    Copy code
    const commentParser = (comments: Comment[]): Comment[] => {
      const commentMap = {};
    
      comments.forEach((comment) => {
        commentMap[comment.id] = comment;
        commentMap[comment.id].children = [];
      });
    
      comments.forEach((comment) => {
        if (comment.parentId !== null) {
          const parent = commentMap[comment.parentId];
          parent.children.push(comment);
        }
      });
    
      return comments.filter((comment) => comment.parentId === null);
    };
    The income data looks like this:
    Copy code
    [
      {
        id: 'ckryupa4i0014sdyazioetibq',
        text: 'Teste',
        createdAt: '05/08/2021',
        parentId: 'ckryqxk8s02772zyagi476b6x'
      },
      {
        id: 'ckryvgpd80063sdyadwo9gyck',
        text: 'Teste 2',
        createdAt: '05/08/2021',
        parentId: 'ckryupa4i0014sdyazioetibq'
      },
      {
        id: 'ckryr0tgh03352zya03qkogtx',
        text: 'You are welcome',
        createdAt: '05/08/2021',
        parentId: 'ckryqw59k02432zyaet0j395g'
      },
      {
        id: 'ckryqxk8s02772zyagi476b6x',
        text: 'dasdasd',
        createdAt: '05/08/2021',
        parentId: null
      },
      {
        id: 'ckryqw59k02432zyaet0j395g',
        text: 'Thanks!',
        createdAt: '05/08/2021',
        parentId: 'ckryp56ga00492zya3yq6kgbm'
      },
      {
        id: 'ckryp56ga00492zya3yq6kgbm',
        text: 'great post!',
        createdAt: '05/08/2021',
        parentId: null
      }
    ]
    Here is my Comment model:
    Copy code
    model Comment {
      id        String    @id @default(cuid())
      text      String
      createdAt DateTime  @default(now()) @map("created_at")
      author    User      @relation(fields: [authorId], references: [id])
      authorId  String    @map("author_id")
      post      Post      @relation(fields: [postId], references: [id])
      postId    String    @map("post_id")
      children  Comment[] @relation("CommentToComment")
      parent    Comment?  @relation("CommentToComment", fields: [parentId], references: [id])
      parentId  String?
    }
    t
    r
    • 3
    • 5
  • c

    Carlos Gomez

    08/05/2021, 8:50 PM
    Hi, I'm able to seed data with a
    seed.ts
    file and
    prisma db seed --preview-feature
    . Is it possible to invoke the seed with parameters? Possibly passed via env vars? Edit: working sample in thread.
    r
    • 2
    • 2
  • g

    Gelo

    08/06/2021, 6:16 AM
    How to fixed this i'm using nextjs
    d
    • 2
    • 3
  • e

    Evan

    08/06/2021, 2:02 PM
    Hi all I ran into an issue where generate no longer works. When generate runs I get this error:
    Copy code
    Prisma schema loaded from prisma/schema.prisma
    Error: binaryTargets.flatMap is not a function
    How I got to this is i renamed a model that had two many to many relationships to a different name. Maybe there’s a better way if I need to rename an entire table besides just renaming it in the schema file and re-running migration/generate? 😅
    👀 1
    j
    • 2
    • 14
  • j

    Jonas

    08/06/2021, 2:19 PM
    In my tests, I have a function to reset my prisma tables. It basically looks like this, but with 20 or more calls:
    Copy code
    async function reset() {
      awais table1.deleteMany({})
      awais table2.deleteMany({})
    }
    r
    • 2
    • 6
  • j

    Jonas

    08/06/2021, 2:20 PM
    Now, I replaced this with the following from the prisma docs:
  • j

    Jonas

    08/06/2021, 2:20 PM
    Copy code
    for (const {
        tablename,
      } of await prismaClient.$queryRaw`SELECT tablename FROM pg_tables WHERE schemaname='public'`) {
        if (tablename !== '_prisma_migrations') {
          try {
            await prismaClient.$queryRaw(`TRUNCATE TABLE "public"."${tablename}" CASCADE;`)
          } catch (error) {
            console.log({ error })
          }
        }
      }
  • j

    Jonas

    08/06/2021, 2:20 PM
    Which is supposed to be more efficient
  • j

    Jonas

    08/06/2021, 2:21 PM
    But for me, it's much, much, much slower
  • j

    Jonas

    08/06/2021, 2:21 PM
    Any idea how that could come about?
  • m

    Mykyta Machekhin

    08/06/2021, 3:57 PM
    Hello friends. According to the Prisma documentation, Every relation must have exactly two relation fields, one on each model. But for my project it becomes inconvenient. The project has already become big. In addition, we are actively working with the prisma schema file, so we want to keep it clean and so that it displays only what we need. On the screen you see an example of one of our models - an account. Many other models are tied to it, but we will never request them directly through the account, so these few lines from the account are simply confusing and bloat an already huge schema file. Is there a way to tell the prisma to stop demanding relationship fields on both sides and add them when reformat?
    👆 1
    r
    • 2
    • 1
  • h

    Halvor

    08/06/2021, 10:05 PM
    My schema looks like this:
    Copy code
    model StatGamemode {
      id              Int              @id @default(autoincrement())
      type            Gamemode
      matches_played  Int              @default(0)
      statGamemodeDM  StatGamemodeDM?
    }
    
    model StatGamemodeDM {
      id             Int          @id @default(autoincrement())
      statGamemode   StatGamemode @relation(fields: [statGamemodeId], references: [id])
      statGamemodeId Int
      kills          Int          @default(0)
    }
    And my old query only summerizing the columns in StatGamemode looks like this:
    Copy code
    const result = await prisma.statGamemode.aggregate({
        _count: {
            _all: true
        },
        _sum: {
            matches_played: true,
            //kills: true
        },
        where: {
            type: gamemode
        }
    });
    How can i summerize the "kills" column from StatGamemodeDM table in the same query?
  • t

    Temm

    08/06/2021, 11:18 PM
    I want to find commands for a development flow where i can • Locally indev: push the current state of the schema to the generator and database (test database as in my local .env) • When committing: Save all changes since the last schema commit as a migration, to cleanly apply the changes on the production server • When pulling on server: Apply the new migrations I thought i already had commands for 1) and 2) 1 being
    prisma db push
    2 being
    prisma migrate dev
    but this doesnt seem to be the case: when running 2 locally, it warns me that database drift has been detected, and it will have to reset my database Can someone help with this? What is the correct way of doing this?
    d
    r
    • 3
    • 18
  • g

    Gelo

    08/07/2021, 3:21 AM
    Any tips on how to write this w/o breaking DRY principles.
  • g

    Gelo

    08/07/2021, 3:21 AM
    Any tips on how to write this w/o breaking DRY principles.
    d
    d
    l
    • 4
    • 5
  • o

    Origin

    08/07/2021, 9:01 PM
    hi, can someone tell me where i can look up @db decorators?
  • o

    Origin

    08/07/2021, 9:02 PM
    i'm trying to upgrade from 27 to 28, have mongodb and @db.array is no more
  • n

    Nathaniel Babalola

    08/08/2021, 1:10 AM
    Please can someone help me , I passed in an object with nested relations, but it's showing me an error of
    Provided List<Json> , expected yyyCreateNestedManyWithoutxxxInput
    How do I fix this please?
    r
    • 2
    • 1
1...467468469...637Latest