OneToMany or ManyToOne?

0

Good evening, I have some basic beginner questions

I need to create a timeline that has the following: What events occurred in a given date range, who was born and who died in this range? I have the Person, Event, and Timeline classes. My Timeline class is the one that determines the date range, so a data range has many events. With this logic I would have to create a one class for Births and another for Deaths or I can create a single to represent this with an attribute to differentiate and how would it be? Since the relationship is OneToMany, the Timeline_Event, Timeline_Numoration, and Timeline_Death tables will be generated. If I do ManyToOne the Event class will have to have the range attribute, as well as the Birth and Death classes. Which of these solutions would be best?

Person { id name of dtFormacy }

Event { id title description // timeline? }

Timeline { id collection interval (events births deaths) addEvento (event) addNavigation (birth) addFoverment (death) }

Birth { id person // timeline? }

Death { id person // timeline? }

// Single class with attribute that differentiates ClassName { id person n / m // timeline? }

EDIT:

I thought so: If a range of the Timeline class has a list of events, it will also have the lists of deaths and births. So I would have to create these classes. The problem in this case is that if the relationship is OneToMany it will automatically be generated plus three tables. If I make ManyToOne the lists will not exist in the Timeline class that will only have the interval attribute and the Event, Birth and Death classes will now have an attribute of type Timeline. The conclusion I've reached that does not matter what kind of relationship I choose I'll have to have one or two classes to represent Births and Deaths

Example of how to stay in the view.

    
asked by anonymous 29.05.2018 / 06:31

1 answer

0

I would do so:

I would have birth and death in the same table, and when I wanted to calculate who was born and who died in a certain time interval I would do a query:

SELECT (campos que ache necessário mostrar) FROM pessoa 
WHERE dataNascimento BETWEEN 'dataA' AND 'dataB'
OR dataFalecimento BETWEEN 'dataA' AND 'dataB'

I hope I have helped.

    
29.05.2018 / 10:30