Learn Prisma Relationships (1-1, 1-m, m-m)

แชร์
ฝัง
  • เผยแพร่เมื่อ 26 ม.ค. 2025

ความคิดเห็น • 27

  • @ThiagoVieira91
    @ThiagoVieira91 2 ปีที่แล้ว +3

    A bright side of being a night lurker on Brazil: having the opportunity to watch awesome tutorials on Aussie afternoon. Superb tutorial again Tom. 👌🏼

  • @gosnooky
    @gosnooky ปีที่แล้ว +2

    I notice you do a lot of dev migrations (around 26:00). I'd recommend using prisma db push to apply changes to the database while in dev and only creating a migration once satisfied everything works as intended. This keeps the migrations history leaner, as it only has major schema changes, no minor ones. Think of it in git terms, you make a lot of commits as you work, then you push or merge once those changes are finalized.
    Note: I know this is done for demonstration purposes, it's just a tip for viewers.

  • @pablom8854
    @pablom8854 ปีที่แล้ว +1

    Thanks for the video! It was just a bit too fast but I'll analyze it with more time

  • @yunhanhuang9304
    @yunhanhuang9304 2 ปีที่แล้ว +2

    Such an amazing and clear tutorial! 🤩

  • @snivels
    @snivels ปีที่แล้ว

    You do incredible work! Love you stuff, especially the more advanced stuff

  • @notko8431
    @notko8431 2 ปีที่แล้ว +2

    absolute legend you are

  • @abdullah-ayy
    @abdullah-ayy ปีที่แล้ว +1

    The many-to-many relation at 13:01 between product and Category doesn't make sense.
    The one that is defined is one-to-many, not many-to-many
    I am assuming you will change that later on in the video.

  • @1ststandardcbse908
    @1ststandardcbse908 2 ปีที่แล้ว +2

    Thank you so much.... Verymuch needed..... I really mean it... Thank you very much

  • @williamcao5139
    @williamcao5139 2 ปีที่แล้ว +2

    Awesome, thanks for your efforts

  • @WhhhhhhjuuuuuH
    @WhhhhhhjuuuuuH 2 ปีที่แล้ว +2

    This is very very very useful

  • @muhammadashfaq913
    @muhammadashfaq913 ปีที่แล้ว +1

    @TomDoesTech What is the VSCode extension you are using that is giving your Prisma Syntax Suggestion? That's really cool bro

    • @RoockYou
      @RoockYou ปีที่แล้ว

      github copilot

  • @Grishopping
    @Grishopping ปีที่แล้ว

    waooo I really liked your video, will you have any video using prism where you compare tables or products ... example I have several stores that sell the same products that can compare the prices of those products and organize them in order from cheapest to most expensive ... examples in that style ...??
    or you could guide me how to do it ... greetings Jose Grillo of Venezuela

  • @notfadeaway6617
    @notfadeaway6617 ปีที่แล้ว +1

    thank you

  • @muhammedubeyd
    @muhammedubeyd ปีที่แล้ว

    Thank you very much for your effort, Does Prisma has model inheritance like BaseEntity implementation, if it has, how can we make it with Postgres, if not, is there any promise in the future to make it in Prisma?

  • @allisfehr
    @allisfehr 2 ปีที่แล้ว

    @19.29, you're mapping your product category to a random category that was already made in the first transaction. If you were seeding a database with an array of users with an array of tasks, do you know how you'd map a the first element of the items array to the first user in the user array? ie. userid: task[task.map((i, index) => index)].id.....I'm getting Type 'number[]' cannot be used as an index type.ts(2538).

    • @TomDoesTech
      @TomDoesTech  2 ปีที่แล้ว

      Map returns an array, so you're trying to get the id prop from an array. You'd need to do task[task.map((i, index) => index)[0]].id

    • @allisfehr
      @allisfehr 2 ปีที่แล้ว

      ​@@TomDoesTech I re-did some of my stuff exactly how you used the index at 24:16 and my errors went away. Unfortunately I'm getting a weird type error now. Have you seen anything like: (property) taskId: { connect: { id: string | undefined; }; } Type '{ connect: { id: string | undefined; }; }' is not assignable to type 'string'.ts(2322)
      My schema is:
      model List {
      id String @id @default(cuid())
      name String @unique
      tasks ListTask[]
      materials Materials[]
      createdAt DateTime @default(now())
      updatedAt DateTime @updatedAt
      }
      model ListTask {
      id String @id @default(cuid())
      taskName String
      taskDescription String
      list List @relation(fields: [listId], references: [id])
      listId String
      }
      My query is:
      const list = await createList();
      //^^ this part creates 10 lists via a transaction in a different file and returns the data
      const task = await prisma.$transaction(
      Array(10)
      .fill(null)
      .map((_, i) => {
      return prisma.task.create({
      data: {
      taskName: "Some name"
      taskDescription: "some description"
      listId: {

    • @allisfehr
      @allisfehr 2 ปีที่แล้ว

      Fixed my own issue. I just had to query list instead of listId

  • @dearvivekkumar
    @dearvivekkumar 2 ปีที่แล้ว

    let's suppose we have a user table and multiple profile tables (CustomerProfile, Admin profile)
    in this case different profiles tables have one relation userID.
    How are you going to tackle the User table ?
    do we need to add multiple fields in users table like CustomerProfile? ,AdminProfile

    • @proletar3799
      @proletar3799 2 ปีที่แล้ว

      lets how the Polymorphic relationships or BelongTo works on ur case.. (but idk ,it will solve ur case or not with prisma. as i heard in a year ago, prisma doesnt supp it yet ).
      i cant elaborate them in details, but i believe i had a same case as urs in the prev proj.

    • @TomDoesTech
      @TomDoesTech  2 ปีที่แล้ว

      Yeah, you could either have a reference on the user for each profile. Or, have a `userProfile` which has all the shared data, then have a reference to each of the distinct tables.
      To be honest, I'm not 100% why you'd want to do this so there might be a nicer solution.

  • @changNoi1337
    @changNoi1337 ปีที่แล้ว

    great tutorial, next time deactivate the autocomplete?

  • @SergiyAntonyuk_PhD
    @SergiyAntonyuk_PhD ปีที่แล้ว

    Very poor explanation, designed for trained users who have already worked with Prisma.

    • @TomDoesTech
      @TomDoesTech  ปีที่แล้ว

      Yes. If you haven't used Prisma you're better off starting with a beginners guide or their docs

  • @musa.ibrahim.80
    @musa.ibrahim.80 ปีที่แล้ว +1

    what are you teaching man? you're not explaining anything. nobody is here to see you coding, we are here to understand stuffs.

  • @виртуоз_ру
    @виртуоз_ру ปีที่แล้ว

    Хорош 👍