this post was submitted on 16 Jun 2024
39 points (93.3% liked)

Programming

17313 readers
397 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities [email protected]



founded 1 year ago
MODERATORS
 

Hii,

I am new to database thing so I am trying to wrap my head around it.

  1. many2one: so in this relationship you will have more than one record in one table which matches to only one record in another table. something like A <-- B. where (<--) is foreign key relationship. so B will have a column which will be mapped to more than one record of A.

  2. one2many: same as many2one but instead now the foreign key constrain will look something like A --> B.

  3. many2many: this one is interesting because this relationship doesn't make use of foreign key directly. to have this relationship between A and B you have to make a third database something like AB_rel. AB_rel will hold values of primary key of A and also primary key of B. so that way we can map those two using AB_rel table.

tell me if I got something wrong :) give me some suggestion <3

you are viewing a single comment's thread
view the rest of the comments
[–] hperrin 14 points 5 months ago (1 children)

One to many: my primary key is other table’s foreign keys.

Many to one: other table’s primary key is my foreign keys.

Many to many: my primary key and other table’s primary key are all foreign keys that connect each other in some other table.

So yeah, you’ve got it right. :)

[–] [email protected] 3 points 5 months ago

This is probably the most straightforward explanation. In many-to-many, I usually have a helper table standing in between which holds the foreign keys