Onetomany or Manytoone?

Asked

Viewed 126 times

0

Good evening, I have some basic beginner questions

I need to create a timeline that has the following: What events occurred in a certain range of dates, 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 class for Births and another for Deaths or can I create a single one to represent this with an attribute to differentiate and how would it be? As the relationship is Onetomany will be generated the tables Timeline_evento, Timeline_nascimento and Timeline_falecimento. If I do Manytoone the Event class will have to have the interval attribute, as well as the Birth and Death classes. Which of these solutions would be better?

Pessoa{ id name dtNascimento dtFalecement }

Event{ id title Description //Timeline? }

Timeline{ id Collection interval(events births deaths) addEvento(event) addNascimento(birth) addFalecimento(death) }

Nascimento{ id person //Timeline? }

Death{ id person //Timeline? }

//Only class with a distinguishing attribute Nomeclasse{ id person n/m //Timeline? }

EDIT:

I thought: If a Timeline class interval has a list of events, it will also have the list of deaths and births. So I would have to create these classes. The problem in this case is that if the relationship is Onetomany will be generated automatically plus three tables. If I do 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 have a Timeline attribute. The conclusion I’ve come to is that no matter what kind of relationship I choose I’ll have to take one or two classes to represent Births and Deaths

Example of how it should look in the view.

inserir a descrição da imagem aqui

1 answer

0

I would do so:

It would have in the same table the birth and the death, and when it wanted to calculate who was born and who died in a certain interval of time would make 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’ve helped.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.