How to model relationships (1-1, 1-m, m-m)

แชร์
ฝัง
  • เผยแพร่เมื่อ 24 ต.ค. 2024

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

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

    I was impressed by the exceptionally clear and to-the-point descriptions of the different relationships - well done!

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

      Glad you enjoyed it!

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

    That's what we need! A simple and concise yet complete and clear explanation and examples of a subject...

  • @frozen_tortus
    @frozen_tortus 8 หลายเดือนก่อน

    Woa, this is some down to the point video, time not waisted watching this. Thanks. Sabin needs a raise, this is so much better then I remember how other guy did it.

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

    I appreciate your work dude. it's definitely too the point and very much time saving.

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

    Thank you for concise presentation! One clarification, though - it seems that one-to-many relationships is a bit wrong - `@unique` annotation for `userId` in `Post` model would actually preclude single user from having multiple posts, so this annotation probably needs to be removed.

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

      Hi, thanks for your input. Can you please point me to the document where this concept is discussed.

    • @pandonia77
      @pandonia77 หลายเดือนก่อน

      You are correct. the @unique attribute needs to be removed otherwise this is a one-to-one

  • @lehung5914
    @lehung5914 5 หลายเดือนก่อน

    Simple and straight forward!. Thanks

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

    So simple and straight to the point, thanks!

  • @josippardon8933
    @josippardon8933 2 หลายเดือนก่อน +1

    In 1:31, are you sure this is one-to-many? You put @unique for userId in Post. This means that in Post table only one row with certain userID can exist, which implies that for specific user only one post can exist.

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

    Thanks, Sabin.
    Looking forward to the self-relation video

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

    These shorts are the best

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

    Clean explanation, thanks

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

    thank you for this , you saved my life

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

    great video sir, keep up

  • @Blue-bb9ro
    @Blue-bb9ro 2 ปีที่แล้ว

    VERY clear to follow along, thanks

  • @lordfranktex5270
    @lordfranktex5270 10 หลายเดือนก่อน

    I appreciate your effort.

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

    Wow, what a tremendous video. Well done!
    I would like to have seen a video where you also explain the different prisma functions, such as findMany, findOne etc.. written in code, intertwined with the use if these different model relations.
    Maybe there is one, will look through the channel.

  • @belkocik
    @belkocik 5 หลายเดือนก่อน

    Straight to the point! However, diagrams would be helpful :)

  • @heliosweb
    @heliosweb 11 หลายเดือนก่อน

    Gonne be super helpful! Thanks!

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

    thanks for the clarification, how can we have multiple prisma schema definition under the same repo/project !?

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

    I think one-to-many had a problem, the ‘userId’ should not be unique, because more than one post can be related to the same user a.k.a. the same ‘userId’

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

    Thanks for the video. Please, which relationship is best to create a relationship between Wishlist, user and products?

  • @BharatBhandari-s5i
    @BharatBhandari-s5i 4 หลายเดือนก่อน

    Brother, In 1-m realtionship model the userId in Post model is @unique
    as 1 user can have multiple post so userId can repeat right?, so it shoudn't be unique

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

    Does it mean that we'd better use the implicit one to keep the prisma config file clear?🤔

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

      👋🏽
      This would be dependent on your use-case. You can create an explicit m-n relation to add more fields to the join table.

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

    Are there any performance implications of implicit m-m relationship?

  • @zaighumhassan7398
    @zaighumhassan7398 10 หลายเดือนก่อน

    Thank you man ❤

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

    Is there something like this? With postgresql
    Role {
    userIds: String[]
    users: User[] @relation(field: 'userIds', references: 'id')
    }

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

    good explanation

  • @diegomedina2359
    @diegomedina2359 3 หลายเดือนก่อน

    4:15 why would be good to handle the relation table by oneself?

  • @aiune2764
    @aiune2764 9 หลายเดือนก่อน

    @PrismaData, isn't it a violation of the constraints to define userId as @unqiue---00:01:23?

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

    muito bom mano. parabéns pelo trabalho.

  • @samuelerbo
    @samuelerbo 9 หลายเดือนก่อน

    Thanks.

  • @PensoMuito
    @PensoMuito 8 หลายเดือนก่อน

    and create action, how can i do?

  • @Mahendrashah-sm1om
    @Mahendrashah-sm1om ปีที่แล้ว

    hey, Does anybody knows how to seperate prisma model in different files?

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

    With the include to get the name instead of just id's you can do something like this:
    include: {
    tags: {
    include: {
    tag: true,
    },
    },
    },

  • @expeng5861
    @expeng5861 21 วันที่ผ่านมา

    my brain already stackoverflow.

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

    To the point 👍

  • @expeng5861
    @expeng5861 21 วันที่ผ่านมา

    greate man

  • @killerdroid99
    @killerdroid99 9 หลายเดือนก่อน

    I thought you were Ben awad for a sec

  • @edwknvlv
    @edwknvlv 5 หลายเดือนก่อน

    Please dont overlap code with your face))

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

    good, thank you boy

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

    i cant find in prisma docs about a zero to many relationships, can somebody help me?
    model infonutriday {
    id String @id @db.VarChar(45)
    date DateTime @db.Date
    portion Float @db.Float
    protein Float @db.Float
    calories Float @db.Float
    grease Float @db.Float
    salt Float @db.Float
    finalizedDay Int @db.TinyInt
    meals Meal[]
    foods Food[]
    infonutriday_has_users infonutriday_has_users[]
    }
    model Food {
    id Int @id @default(autoincrement())
    name String
    portion Int
    protein Float @db.Float
    calories Float @db.Float
    grease Float @db.Float
    salt Float @db.Float
    image String?
    infonutridayId String?
    infonutriday infonutriday? @relation(fields: [infonutridayId], references: [id])
    meals_has_foods meals_has_foods[]
    users_has_foods users_has_foods[]
    @@map("foods")
    }
    model Meal {
    id Int @id @default(autoincrement())
    name String
    isMeal Int @db.TinyInt
    portion Int
    protein Float @db.Float
    calories Float @db.Float
    grease Float @db.Float
    salt Float @db.Float
    image String?
    infonutridayId String?
    infonutriday infonutriday? @relation(fields: [infonutridayId], references: [id])
    meals_has_foods meals_has_foods[]
    users_has_meals users_has_meals[]
    @@map("meals")
    }
    Infonutriday can have 0 or many foods or infonutriday can have 0 or many meals.
    Any suggestion ?

  • @lordfranktex5270
    @lordfranktex5270 10 หลายเดือนก่อน

    Thanks.