Relationship between ORM tables

0

I'm having a question, regarding ORM, I use Doctrine, but understanding ORM would help. The relation of idAninal of table consulta , with table Animal , would be ManyToMany , ManyToOne , or OneToMany ? Conform UML below:

    
asked by anonymous 24.04.2017 / 03:40

1 answer

1

From the UML all we can know is that it is not a ManyToMany relationship, since each query has only one animal, since it holds the ID of the animal.

The difference between OneToMany and ManyToOne occurs at the ORM level, there is no difference in terms of bank structure. If it is the side one of the interface that keeps the reference for many it is said that it is a OneToMany interface. If many references one, then it's 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 by making a c.animal. That's the OneToMany case. Another possibility would be to create the variable "queries" in the "animal" class (which would represent the animal table). So you would access the queries from the animal, doing an a.consultas. That would be ManyToOne.

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

    
24.04.2017 / 06:45