본문 바로가기

STACKOVERFLOW 1일 1질문

다섯 번째 질문. Difference Between One-to-Many, Many-to-One and Many-to-Many?

https://stackoverflow.com/questions/3113885/difference-between-one-to-many-many-to-one-and-many-to-many

 

Difference Between One-to-Many, Many-to-One and Many-to-Many?

Ok so this is probably a trivial question but I'm having trouble visualizing and understanding the differences and when to use each. I'm also a little unclear as to how concepts like uni-directiona...

stackoverflow.com

 

질문:

...더보기

Ok so this is probably a trivial question but I'm having trouble visualizing and understanding the differences and when to use each. I'm also a little unclear as to how concepts like uni-directional and bi-directional mappings affect the one-to-many/many-to-many relationships. I'm using Hibernate right now so any explanation that's ORM related will be helpful.

 

사소한 질문일 수 있지만, one-to-manymany-to-many의 차이점을 이해하고 시각화하는데 어려움이 있습니다.

또 단방향, 양방향 매핑이 다대 다,  one-to-many 관계에 영향을 줄 수 있는지 분명히 이해가 가지 않습니다.

 

 

답: 

...더보기

Looks like everyone is answering One-to-many vs Many-to-many:

The difference between One-to-many, Many-to-one and Many-to-Many is:

모든 사람들이 One-to-many vs Many-to-many에 대답하고 있는 것처럼 보입니다.

One-to-many, Many-to-one and Many-to-Many의 차이는 다음과 같습니다.

 

 

...더보기

One-to-many vs Many-to-one is a matter of perspective. Unidirectional vs Bidirectional will not affect the mapping but will make difference on how you can access your data.

  • In One-to-many the many side will keep reference of the one side. A good example is "A person has many skills". In this case Person is the one side and Skill is the many side. There will be a column person_id in the table skills.

One-to-many vs Many-to-one는 관점의 문제입니다. 단방향(unidirectional)과 양뱡향(bidirectional)은 매핑에 영향을 주지 않습니다. 

 

Many-to-one 경우는, Pesron은 단방향이지만, Skills은 다방향인 부분입니다. 그러므로, Skill table에 person_id가 있을 것입니다.

즉, 사람은 한명이지만(One), 가지고 있는 기술의 수는 많습니다.(Many)

...더보기
In Many-to-one the many side will be our point of reference. For example, "A User has an Address". In our system a lot of users might share an address( a number of people might share the same block number, for instance). In that case the address_id column in the users table is will be shared by more than one users rows. In this case we say that users and addresseshave Many-to-one relationship.

 Many-to-one가 우리가 주로 다루는 데이터 모델입니다.

 

예를 들자면, "한 사용자가 주소를 가지고 있다" 라고 생각해봅시다.

우리의 시스템에서는 많은 유저들이 주소들을 공유하고 있습니다.

예를들어 많은 사람들이 같은 블록 넘버를 일시적으로 공유하는 것처럼 말입니다.

 

그러한 경우 유저 테이블 안의 주소의 id  컬럼은 한 사람의 유저보다 많은 사람들에게 공유될 것입니다.

이러한 경우를 유저와 주소가 다대 일의 관계를 가지고 있다고합니다.

즉, 유저는 많지만(Many), 연결되는 주소는 하나입니다.(One)

 

...더보기

In unidirectional, a User will have Address address. Bidirectional will have an additional List<User> users in the Address class.

단방향(unidirectional)에서는, User가 Adress 테이블의 address 칼럼을 이용합니다.

양방향(bi-direction)에서는 추가적으로 주소 클래스에서 User테이블의 user 칼럼을 가질 수 있습니다.

 

 

...더보기
  • In Many-to-Many members of each party can hold a reference to an arbitrary number of members of the other party. To achieve this a look up table is used. Example for this is the relationship between doctors and patients. A doctor can have many patients and vice versa.

Many-to-Many에서는,서로 다른 테이블의 칼럼을 얼마든지 참조할 수 있습니다.

이것을 실행하기 위해서는 lookup table(Connect, Junction)이 사용됩니다.  

예를 들어, 이 관계는 환자와 의사의 관계와 같습니다.

즉, 의사는 많은 환자들을 가질 수 있으며(Many)

반대로, 환자들도 많은 수의 의사를 가질 수 있습니다.(Many)