1

First Example:

Let's assume I have a two classes : Employee and Division.

the (bidirectional) relationship between the classes is :

An employee works in one division [OneToOne] and any given division has one or more employees working in it. [OneToMany]

===========

Second Example:

Let's assume I have a two classes again : Employee and Task

the (bidirectional) relationship between the classes is :

An employee is assigned one or more tasks [OneToMany] and each task is assigned to zero or more employees[ManyToOne]

but this site : http://www.agiledata.org/essays/mappingObjects.html#TypesOfRelationships says the fist relationship is OneToMany and the second is ManyToMany

So Where I'm getting this wrong. I don't see any use for a ManyToMany Relationship

PS: I've read this Difference Between One-to-Many, Many-to-One and Many-to-Many?

1 Answers1

1

Second example:

Employees:

  1. Mohammed
  2. Bob

Tasks:

  1. Code great app
  2. Document your app

Mohammed can take several tasks (one-to-many) but now also a task can be taken by several employees (e.g. Bob can help you to do that great app).

So when you see that from one side of a relationship, it is useful a one-to-many (it is useful to assign several tasks to an employee), but also from the other side of the relationship there is value to have a one-to-many (several employees can team to do that great app), then you got a Many-to-Many.