Relationship between ORM tables

Asked

Viewed 55 times

0

I have a doubt, regarding ORM, I use the Doctrine, but understanding of ORM would already help. The relationship of the idAninal table consulta, with the table Animal, would be, ManyToMany, ManyToOne, or OneToMany? Conforms UML below:

inserir a descrição da imagem aqui

1 answer

1


From the UML all we can know is that it is not a Manytomany relationship, because each query has only one animal, since it keeps the animal ID.

The difference between Onetomany and Manytoone occurs at the level of the ORM, there is no difference in terms of bank structure. If it is the one side of the relationship that holds the reference to the Many it is said to be a Onetomany relation. If the Many references the one, then it is a Manytoone.

For example, when coding this in your ORM, you can choose to create an "animal" variable in the "query" class (which would represent the table), and thus access the animal from each query c, making a c.animal. This is the case Onetomany. Another possibility would be to create the variable "queries" in the "animal" class (which would represent the animal table). So you would access the consultations from the animal, making an a.consultas. This would be the Manytoone.

If you create both references simultaneously, then it becomes a bidirectional relationship.

Browser other questions tagged

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