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

    Rich Starkie

    01/24/2022, 10:47 PM
    Hey folks, having a problem with writing data to relationship fields. Fields are (of course) defined in the schema both ends are 
    []
    I've tried what the docs say to connect to the remote field as the fields are populated earlier in the script, but I've also tried a create with the same results. Here's a couple of code blocks that may help ...
    Copy code
    await prisma.<table>.create{(
    ...
    releaseShelf:{ // releaseShelf is the name of the Relation in Schema - linked table is libraryShelves
    connect: {shelfId: variable}, // shelfId is the PK field of the table
    }
    )}
    Schema Main Table
    Copy code
    model libraryReleases {
      releaseId              String   @id @db.VarChar(255)
      releaseMasterId        String   @default("-1") @db.VarChar(255)
      releaseDiscogsPage     String   @default("#") @db.VarChar(1024)
      releaseDiscogsImageUrl String   @default("#") @db.VarChar(1024)
      releaseLocalImage      String   @default("images/coming_soon.png") @db.VarChar(1024)
      releaseTitle           String   @db.VarChar(512)
      releaseSortLetter      String   @default("-") @db.VarChar(1)
      releaseSortName        String   @default("-") @db.VarChar(512)
      releaseCatalogueNumber String   @default("-") @db.VarChar(512)
      releaseYear            Int      @default(0)
      releaseNumberDiscs     Int      @default(0)
      releaseReviewRating    Decimal  @default(0) @db.Decimal(2, 1)
      releaseTimesPlayed     Int      @default(0)
      releaseLastPlayed      DateTime @default(dbgenerated("'1970-01-01 01:00:01+01'::timestamp with time zone")) @db.Timestamptz(6)
      releaseAddedToDiscogs  DateTime @default(dbgenerated("'1970-01-01 01:00:01+01'::timestamp with time zone")) @db.Timestamptz(6)
      releaseTracksAdded     DateTime @default(dbgenerated("'1970-01-01 01:00:01+01'::timestamp with time zone")) @db.Timestamptz(6)
      releaseDecade50s       Boolean? @default(false)
      releaseDecade60s       Boolean? @default(false)
      releaseDecade70s       Boolean? @default(false)
      releaseDecade80s       Boolean? @default(false)
      releaseDecade90s       Boolean? @default(false)
      releaseDecade00s       Boolean? @default(false)
      releaseDecade10s       Boolean? @default(false)
      releaseDecade20s       Boolean? @default(false)
      releaseLibrary         Boolean? @default(false)
      releaseWantlist        Boolean? @default(false)
      releaseSlug            String   @unique @db.VarChar(300)
      createdAt              DateTime @db.Timestamptz(6)
      updatedAt              DateTime @db.Timestamptz(6)
    
      releaseArtists           libraryArtists[]
      releaseFormats           libraryFormats[]
      releaseStyle             libraryStyles[]
      releaseGenres            libraryGenres[]
      releaseCurrentLocation   libraryLocations[]          @relation(name: "currentLocation")
      releaseLibraryLocation   libraryLocations[]          @relation(name: "libraryLocation")
      releaseRecordLabel       libraryRecordLabels[]
      releaseShelf             libraryShelves[]
      releaseTracks            libraryTracks[]
      releaseUnavailableReason libraryUnavailableReasons[] @relation(name: "releaseUnavailable")
    }
    Shelf Table
    Copy code
    model libraryShelves {
      shelfId      String            @id @db.VarChar(255)
      shelfName    String            @db.VarChar(255)
      shelfCount   Int               @default(0)
      shelfSlug    String            @unique @db.VarChar(300)
      createdAt    DateTime          @db.Timestamptz(6)
      updatedAt    DateTime          @db.Timestamptz(6)
      shelfRelease libraryReleases[]
    }
    This gives an error :
    Copy code
    Unknown arg `releaseShelf` in data.releaseShelf for type libraryReleasesUncheckedCreateInput.
    Any help much appreciated Thanks 😄
  • n

    n

    01/25/2022, 12:17 AM
    How do I access the Decimal type from the lib (not a class for my type definition)?
    Copy code
    Type 'Account' is not assignable to type 'AccountModel'.
      Types of property 'balance' are incompatible.
        Type 'Decimal' is not assignable to type 'string | number'.
          Type 'Decimal' is not assignable to type 'number'.ts(2322)
  • c

    Chuan WU

    01/25/2022, 4:56 AM
    Hi Could some one help me on this case? Suppose I have three tables: Product, SettingKey, SettingValue. The settingKey stores what kind of setting a product could have. How could I query all properties with key & value of a product?
    Copy code
    model SettingKey {
      id        Int       @id @default(autoincrement())
      productType  ProductType
      key       String
      label     String
      valueType DataType
      Setting   Setting[]
    }
    
    model SettingValue {
      id        Int       @id @default(autoincrement())
      productId  Int
      keyId     Int
      value     String
      product    Product?   @relation(fields: [productId], references: [id])
      @@index([productId], name: "fk_product")
      key       SettingKey? @relation(fields: [keyId], references: [id])
      @@index([keyId], name: "fk_key")
    }
  • a

    ArcticSpaceFox

    01/25/2022, 4:50 PM
    Hello dear Prisma Community, anybody up for a challenge? How would you represent the following Relational Chart in the Prisma Scheme?
  • w

    William Albright

    01/25/2022, 5:51 PM
    hi! can anyone help me figure this out? https://gist.github.com/ewilliam/a2a3fb9b917fcb3a1b301506a3deb016 id think relation create would work? but looks like i have to create a person record on its own and connect instead?
  • w

    William Albright

    01/25/2022, 5:59 PM
    ah just saw the GreetBot message. posted in the github, sorry yall
  • o

    Okan Yıldırım

    01/25/2022, 7:25 PM
    Hello
  • o

    Okan Yıldırım

    01/25/2022, 7:25 PM
    Is this a good place to ask questions?
    f
    • 2
    • 2
  • o

    Okan Yıldırım

    01/25/2022, 7:25 PM
    Um, I am trying nexus-prisma currently.
  • o

    Okan Yıldırım

    01/25/2022, 7:26 PM
    It works a little bit different for getting data
  • f

    Franco Roura

    01/25/2022, 7:26 PM
    Hi folks, I want to write some unit tests to make sure every camelCase property of my
    schema.prisma
    file has a @map('snake_case') equivalent. Does prisma have any kind of AST builtin tool or should I just read the file and parse it with js?
  • o

    Okan Yıldırım

    01/25/2022, 7:27 PM
    It firstly gets all Posts, for example: `prisma.post.findMany()`then for the relationships, it does something like this;
  • o

    Okan Yıldırım

    01/25/2022, 7:27 PM
    prisma.post.findUnique({id: 1, select: { user: true } })
  • o

    Okan Yıldırım

    01/25/2022, 7:27 PM
    basically it gets all posts first, then gets their users one by one
  • o

    Okan Yıldırım

    01/25/2022, 7:27 PM
    do you think that there is any performance disadvantage of doing this?
    f
    • 2
    • 6
  • a

    ador

    01/25/2022, 9:14 PM
    hey
  • o

    Oleg Komarov

    01/25/2022, 9:18 PM
    Hi, is there a way to prefix at generation time the @prisma/client model names with e.g. a
    Db
    so it’s clear that the queried object is of type e.g. DbUser and not the any other mapping in the code? Just wasted 2 hours debugging an obscure issue to find out I forgot to map the database type to the requested type since they have the same name 🤦‍♂️
    😅 1
    prisma cool 1
  • a

    ador

    01/25/2022, 9:20 PM
    I wanted to ask a question. so I'm trying to pull information from the database with prisma by doing this:
    Copy code
    const categories = await this.tableIds.categories.findMany()
    with tableIds it works just fine, but when I try
    categories
    :
    Copy code
    const categories = await this.prisma.categories.findMany()
    it just
    Cannot read properties of undefined (reading 'findMany')
    both are models in
    schema.prisma
  • a

    ador

    01/25/2022, 9:22 PM
    out of all models only
    categories
    and
    products
    doesn't work for some reason
    d
    • 2
    • 4
  • a

    ador

    01/25/2022, 9:22 PM
    yes they exist in the database
  • w

    Wade McDaniel

    01/25/2022, 11:41 PM
    Anyone have trouble getting prisma to build the linux binaries in a windows environment using
    binaryTargets = ["native", "rhel-openssl-1.0.x"]
    ? I'd like to generate the linux binaries so I can upload them to a linux serverless instance, but all I get in windows is "native" binaries.
    n
    • 2
    • 2
  • d

    Darian Sampare

    01/25/2022, 11:52 PM
    Hey everyone! We're looking to make the switch to Prisma from TypeORM at my company (it has come so far since I last saw it in Prisma 1, congrats to the team!) and I'm curious if anyone has found a workaround for model/entity subscribers/hooks. For example TypeORM supports subscribing to saves, deletes and other events where you can run some clean up code. We have a few cases where we need to fire off requests to 3rd party services when a model is deleted directly or through a cascade. This is really common in larger frameworks supporting the active record pattern, so I'm curious if anyone has tackled this with any success when they switched to Prisma.
    n
    • 2
    • 1
  • a

    ador

    01/26/2022, 3:46 PM
    can I create databases with Prisma?
    n
    • 2
    • 4
  • b

    Barnaby

    01/26/2022, 4:02 PM
    no, just tables and columns within a single database afaik
  • s

    sampoder

    01/26/2022, 4:06 PM
    thank you Prisma for the Christmas / New Years card! Happy (very late) holidays to you all!
    💚 1
  • a

    André

    01/26/2022, 4:19 PM
    Hiring Developers with experience in Javascript and React, React Native / VueJS Make account and adding more info inside the Settings like CV, Projects, ... On website => https://startups-hire.com I Will reach you later
    🤨 1
  • s

    Sebastian Rindom

    01/26/2022, 4:55 PM
    Hey everyone! Have been playing around with migrating github.com/medusajs/medusa from TypeORM to Prisma, but not sure how to approach it given the architecture we have. Will try to explain in a few steps here: • We have a core NPM package that contains core db entities • We have multiple plugins that may or may not include additional db entities • Users of the Medusa install the core package + any plugins that they may want • On bootstrap the core package collects all db entities + all migrations across core and plugins •
    medusa migrations run
     will ensure that all missing migrations from core + plugins are applied Trying to map this to Prisma my thinking so far is this: • Core + Plugins will have 
    schema.prisma
    • Core + Plugins will have migrations • *Core will programmatically collect migrations and call Prisma Migrate • *Core programatically creates a Prisma client that is unique to the user’s core + plugins combination My questions are about the last two steps marked with * - 1) are these steps possible and recommended and 2) are there alternative approaches that would be better
    👀 1
  • o

    Omar

    01/26/2022, 5:49 PM
    Fireship just made a nice video about Prisma in 100 seconds

    https://www.youtube.com/watch?v=rLRIB6AF2Dg&amp;ab_channel=Fireship▾

    prisma rainbow 2
    prisma dark 4
    🔥 4
    💚 1
    fast parrot 1
  • c

    Chris Tsongas

    01/26/2022, 7:08 PM
    Has anyone successfully installed Prisma in Turborepo's
    packages
    folder for use by multiple
    apps
    ?
    f
    • 2
    • 1
  • m

    Matt Furden

    01/26/2022, 9:18 PM
    Hi! I've been trying to map multiple fields to the same model and I've read about needing to add name etc to disambiguate but I'm wanting to map to the same field in the shared model, is there a way to accomplish that?
    • 1
    • 4
1...537538539...637Latest