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

    Yaakov

    08/11/2022, 2:46 PM
    Hi, is there any way to make a nullable column unique?
    ✅ 1
    👀 1
    n
    • 2
    • 3
  • r

    Roded Konforty

    08/11/2022, 3:23 PM
    Hi all, and good morning 🙂
  • r

    Roded Konforty

    08/11/2022, 3:24 PM
    I wanted to reach you guys before keeping my raw query.
  • r

    Roded Konforty

    08/11/2022, 3:24 PM
    I'm trying to have a find many distinct with count is that possible?
    ✅ 1
    a
    • 2
    • 7
  • r

    Roded Konforty

    08/11/2022, 3:24 PM
    Or groupby with include, that will also do.
  • t

    Ted Joe

    08/11/2022, 3:36 PM
    Is it possible to add an array of records to a field in a table? So something like this:
    Copy code
    User {
      id: 394993
      ...
      userAddress: [Address, Address, Address]
    }
    
    Address {
      id: 393932
      ...
    }
    ✅ 1
    h
    n
    • 3
    • 5
  • m

    Michael Gates

    08/11/2022, 6:37 PM
    How can I download all engine variations? Upon running Yarn install, I realized it only downloads the engine for my current system. But if I switch to another system and clone the repo while my dependencies are checked in (with Yarn), prisma won't work because the engine versions between the two machines are different.
    In the postinall hook of this package, all engines available for the current platform are downloaded from the Prisma CDN
    But I want to download for all platforms, not just the current.
    👀 1
    a
    • 2
    • 13
  • h

    heliosalves

    08/11/2022, 7:12 PM
    Hi, I’m quite new to Prisma and I’m wondering how I could create a model for a many-to-many relationship that works as follow I want to have a model
    Quotation
    and one
    Invoice
    , these two models are very similar and I can create a quotation and once the quotation is accepted, I can create an invoice for this quotation. When I create the quotation I’d like to be able to add sections and items to these sections. When I create an invoice I can either attach a quotation to this invoice or add sections and items to these sections. I took a look at the documentation on Prisma for the many-to-many relationships https://www.prisma.io/docs/concepts/components/prisma-schema/relations/many-to-many-relations, but I’m unsure how to do this when two tables depend on this. In my case I want to have a many-to-many relationship between
    Quotation
    ,
    Section
    and
    SectionItem
    and
    Invoice
    ,
    Section
    SectionItem
    Here are the models I’ve created so far
    Copy code
    model Client {
      id                  String      @id @default(uuid())
      name                String
      street              String
      postalCode          String
      city                String
      email               String
      typeId              String
      type                ClientType  @relation(fields: [typeId], references: [id], onDelete: Restrict)
      createdAt           DateTime    @default(now())
      updatedAt           DateTime    @updatedAt
      phoneNumberMobile   String?
      phoneNumberLandLine String?
      invoices            Invoice[]
      quotations          Quotation[]
    }
    
    model ClientType {
      id      String   @id @default(uuid())
      value   String
      clients Client[]
    }
    
    model Category {
      id       String    @id @default(uuid())
      value    String
      stocks   Stock[]
      services Service[]
    }
    
    model Stock {
      id         String   @id @default(uuid())
      name       String
      quantity   Int      @default(0)
      price      Float    @default(0)
      categoryId String
      category   Category @relation(fields: [categoryId], references: [id], onDelete: Restrict)
    }
    
    model Invoice {
      id              String        @id @default(uuid())
      number          Int           @unique
      createdAt       DateTime      @default(now())
      updatedAt       DateTime      @updatedAt
      invoiceStatusId String
      status          InvoiceStatus @relation(fields: [invoiceStatusId], references: [id], onDelete: Restrict)
      dueOn           DateTime
      validUntil      DateTime
      clientId        String
      client          Client        @relation(fields: [clientId], references: [id], onDelete: NoAction)
      quotationId     String?       @unique
      quotation       Quotation?    @relation(fields: [quotationId], references: [id], onDelete: NoAction)
      sections        Section[]
    }
    
    model Quotation {
      id              String    @id @default(uuid())
      number          Int
      createdAt       DateTime  @default(now())
      updatedAt       DateTime  @updatedAt
      invoiceStatusId String
      validUntil      DateTime
      clientId        String
      client          Client    @relation(fields: [clientId], references: [id], onDelete: NoAction)
      invoice         Invoice?
      sections        Section[]
    }
    
    model InvoiceStatus {
      id       String    @id @default(uuid())
      value    String
      invoices Invoice[]
    }
    
    model Service {
      id         String   @id @default(uuid())
      name       String
      price      Float
      categoryId String
      category   Category @relation(fields: [categoryId], references: [id], onDelete: Restrict)
    }
    
    model SectionUnit {
      id              String    @id @default(uuid())
      value           String
      serviceSections Section[]
    }
    
    model SectionItem {
      id               String    @id @default(uuid())
      name             String
      description      String    @db.Text
      serviceSectionId String
      sections         Section[]
    }
    
    model Section {
      id          String        @id @default(uuid())
      name        String
      items       SectionItem[]
      unitId      String
      unit        SectionUnit   @relation(fields: [unitId], references: [id], onDelete: Restrict)
      quotationId String?
      quotation   Quotation?    @relation(fields: [quotationId], references: [id], onDelete: NoAction)
      invoiceId   String?
      invoice     Invoice?      @relation(fields: [invoiceId], references: [id], onDelete: NoAction)
    }
    I’m not sure if this is the correct approach, any help would be appreciated 🙂 Thank you
    j
    • 2
    • 5
  • t

    Tyler C

    08/11/2022, 7:31 PM
    When using `import {Prisma} from '@prisma/client'. I am unable to see the types such as Prisma.UserWhereUniqueInput, etc. No autocompletion from VScode. Is there something I need to do in order to see these 'types' for my models. Thanks in advance.
    ✅ 1
    r
    • 2
    • 15
  • a

    Albert Montolio

    08/11/2022, 8:32 PM
    Hi there, I’m a new-comer by Prisma, I have a question related to
    date
    type using
    nestjs
    app with
    prisma
    and using
    postgresql
    as
    db
    . I opened this discussion on prisma’s github for further details on the question. Basically I’m struggling to understand what
    date object
    to pass to the
    this.prisma.user.create({ data: {date: XXX}})
    . I define the field
    date
    as
    DateTime @db.Date
    in thet prisma schema. But
    Postgresql
    wants a date object with format
    'YYYY-MM-DD',
    but I’m in a
    nestjs
    app, I can’t pass a string, since prisma is expecting a date object. If I do sth like
    new Date()
    with whatever format, like iso and so on, it stills doesn’t correspond to the
    'YYYY-MM-DD'
    , I can only obtain this if I pass a string, but then prisma complains. Could someone guide me on that topic? In the docu I just found this, but this just works purely with postgresql, not with the prisma client. Thanks!
    👀 1
    n
    v
    • 3
    • 2
  • d

    Dave Edelhart

    08/11/2022, 10:33 PM
    The fact that you have to know the name of your indexes in order to do “where” against a unique pair of fields is a very bad design decision. You should be able to define the where fields without having to introspect the index structure.
    ✅ 1
    j
    m
    +2
    • 5
    • 5
  • j

    Justin F

    08/12/2022, 1:43 AM
    Alright, I need to seed my postgresql database from a csv. How should I approach this?
    ✅ 1
    j
    n
    • 3
    • 2
  • n

    Nurul

    08/16/2022, 9:03 AM
    Continuing conversation here: https://prisma.slack.com/archives/CA491RJH0/p1660640566629239?thread_ts=1660249957.343099&cid=CA491RJH0
  • e

    Enzot

    08/12/2022, 9:17 AM
    It is normal behavior that Prisma return e.g.
    100n
    for BigInt? I wonder if I can somehow remove that
    n
    automatically
    ✅ 1
    n
    d
    • 3
    • 5
  • j

    Jhonathan Campos

    08/12/2022, 9:19 AM
    Newbie working student here. I would like to understand better a typescript error I am dealing with. Is anyone available for a private chat quick talk? Thanks! mario luigi dance
    👀 1
    n
    v
    • 3
    • 2
  • h

    Hussam Khatib

    08/12/2022, 9:35 AM
    Hey there, Is there a way to use
    distinct
    where a column can be null too. Expected Behaviour : if value is not null , perform using it normal behaviour of distinct. If value is null I want this to be returned as well.
  • b

    Bastien Etienne

    08/12/2022, 10:23 AM
    Hello , have a little problem i use
    upsert
    for Create if id not exist. So actually update work fine but when id not exist , the create part return me this error :
    Copy code
    :42:29) {
      code: 'P2023',
      clientVersion: '4.0.0',
      meta: {
        message: 'Error creating UUID, invalid length: expected one of [36, 32], found 35'
      }
    }
    This is the code
    Copy code
    const updateFeature = await prisma.feature.upsert({
            where: {
              id: props.idFeature,
            },
            update: {
              cibest_role_id: roleId.id,
              create: props.create,
              read: props.read,
              update: props.update,
              delete: props.delete,
              service_name: props.service_name,
            },
            create: {
              cibest_role_id: roleId.id,
              create: props.create,
              read: props.read,
              update: props.update,
              delete: props.delete,
              service_name: props.service_name,
            },
          });
    this is the feature model
    Copy code
    model feature {
      id             String       @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
      date_created   DateTime     @default(now()) @db.Timestamp(6)
      service_name   service_name
      create         Boolean      @default(false)
      read           Boolean      @default(false)
      update         Boolean      @default(false)
      delete         Boolean      @default(false)
      cibest_role_id String       @db.Uuid
      iconId         String?      @db.Uuid
      cibest_role    cibest_role  @relation(fields: [cibest_role_id], references: [id])
      icon           icon?        @relation(fields: [iconId], references: [id])
    }
    ✅ 1
    👀 1
    n
    • 2
    • 15
  • p

    Phorcys

    08/12/2022, 11:50 AM
    hey! I'm using Prisma for a school project and in some older projects, really loving it so far. I was wondering how I would achieve something like that :
    Copy code
    model Classroom {
      id String @id @default(cuid())
    
      type     Int      @default(0)
      name     String
    
      teachers Teacher[] // when a teacher is added, append to the teacher's "classes" attribute
    }
    
    model Teacher {
      id String @id @default(cuid())
    
      user   User   @relation(fields: [userId], references: [id], onDelete: Cascade)
      userId String @unique
      
      classes Classroom[] // when a class is added, add the teacher to the matching class' "teachers" attribute
    
      subjects Subject[]
    }
    b
    n
    • 3
    • 4
  • p

    Phorcys

    08/12/2022, 11:52 AM
    also, is it possible to make the datasource provider tied to an env variable or a config file ?
    ✅ 1
    n
    b
    • 3
    • 4
  • m

    Michael Jay

    08/12/2022, 1:18 PM
    Can anyone tell me what version of the MongoDB native driver that Prisma is built on for MongoDB use?
    ✅ 1
    n
    • 2
    • 2
  • s

    Slackbot

    08/12/2022, 5:33 PM
    This message was deleted.
    n
    • 2
    • 1
  • h

    heliosalves

    08/12/2022, 6:31 PM
    Hi, I’m quite new to Prisma and databases actually 🙂 I’d like to know if it’s possible to have a table that is linked to two tables. I have one table
    Section
    and this table is linked to another table
    SectionItem
    , I have two other tables,
    Quotation
    and
    Invoice
    and I want to be able to add sections and sectionItems to either
    Quotation
    or
    Invoice
    . Is this even possible? How could I do this in Prisma? How can I create a model that allows me to do this? Thank you
    ✅ 1
    c
    • 2
    • 2
  • n

    nick

    08/12/2022, 7:56 PM
    how can i index a non-unique field in typescript prisma schemas?
    👀 1
    n
    v
    a
    • 4
    • 5
  • a

    Abdul Khan

    08/12/2022, 11:22 PM
    im able to add foreign items programtically but unable to do it on prisma studio. is there a workaround for this?
    👀 2
    r
    • 2
    • 1
  • a

    Abdul Khan

    08/12/2022, 11:22 PM
    Copy code
    Type: undefined
    Message: 
    Invalid `prisma.menu.create()` invocation:
    
    {
      data: {
        id: 4,
        ~~
        name: 'Brunch',
        resteraunt: {
          connect: {
            id: 1
          }
        }
      },
      select: {
        id: true,
        name: true,
        resteraunt: true,
        resterauntId: true
      }
    }
    
    Unknown arg `id` in data.id for type MenuCreateInput. Available args:
    
    type MenuCreateInput {
      name?: String | Null
      resteraunt: ResterauntCreateNestedOneWithoutMenuInput
    }
    
    
    
    Code: undefined
    
    Query:
    [object Object]
  • a

    Abdul Khan

    08/12/2022, 11:24 PM
    also side note: i corrected the spelling of
    menu
    and still resulted in the same error
    👀 1
    n
    v
    • 3
    • 2
  • i

    Italo Gama

    08/13/2022, 1:38 AM
    Hey guys, i’m getting this error: The provided value for the column is too long for the column’s type. Column: (not available) Any help?
    ✅ 1
    r
    a
    • 3
    • 6
  • i

    Italo Gama

    08/13/2022, 2:16 AM
    my field has varchar(255) already. i dont know why i’m getting this error
    ✅ 1
    n
    • 2
    • 1
  • h

    Hussam Khatib

    08/13/2022, 4:20 AM
    What is the best a way to use
    OR
    filter in where clause in such way that the first condition in
    OR
    is checked throughout the db and if it does not exist try with the second one.
    Copy code
    const result = await prisma.findFist({
       where:{
          OR:[
             {"condition 1"},{"condition 2"}
         ]
       }
    })
    If filter condition 1 is not matched with any record , then only try for condition 2
    👀 1
    n
    v
    • 3
    • 2
  • c

    Clément Guibout

    08/13/2022, 2:26 PM
    Hello I have a problem with prisma autoincrement using postgres my model is:
    Copy code
    model Event {
      evt_id           String        @id @default(uuid())
      ...
1...607608609...637Latest