-1
There are common problems that I see a lot of difficulty to deal with Orms, and ignoring a native way I decided to ask what is the best way to deal with these using Typeorm in project. Today I have a project that deals with generalization and person specialization, basically I have a table Pessoa
where I store the id
or enrollment, I create relationships with phone numbers, emails and addresses, and I have two other tables that inherit the primary key of the person who is the pessoa_juridica
and pessoa_fisica
, bearing in mind that my application works with these two types of people. The problem is how I should implement this using an ORM like Typeorm?
To make the model more explicit:
in the image we have:
- A relationship
1-N
tablepessoa
for tabletelefone
- A relationship
1-N
tablepessoa
for tableemail
- A relationship
1-1
tablepessoa
for tablepessoa_fisica
- A relationship
1-1
tablepessoa
for tablepessoa_juridica
The question there is also in, a natural person can not be a legal person at the same time and vice versa.
although it has an objective point in your question, part of it can be based on opinions, and honestly an entity with 1 attribute does not make sense, in my humble opinion ok? could take the attribute "name" there, and remove the "name" and "name_fantasi", that would make sense. Now "a natural person cannot be a legal person at the same time" this is solved by the right model itself? a PF has no CNPJ or Registration, just as a PJ has no CPF or RG. But already researched on the
@TableInheritance
and@ChildEntity
? They should solve the implementation problem of this model– Ricardo Pontual
This Ricardo, I’m actually setting up an api for an existing bank and it’s modeled on this vein, so I gave the example, basically the entity person only keeps the ids, and the entities of physical person and person Urica inherit these ids as pk, other entities such as telephone and email for example related person, so daughter entities inherit these relationships
– Saulo Lins