I have a question about sqlalchemy and DB normalization.
I have a table called Accounts, and 2 kinds of persons, Natural_Persons and Legal_Persons.
I need to relate an account to just one person at a time.
For example, the account ID 4 is related with the Natural_Person ID 5.
But... How can I know when I query that information, if the ID 5 in the account record is from a Natural Person or a Legal one?
The simplest solution (for me at the moment) is to add a new field to the Accounts table called person_type, and to use, for example, a char to differentiate them.
So now I have a record in the accounts table with the following data:
account_id = 4
person_id = 5
person_type = N
But now I want to use the DB with sqlalchemy.
If I load an account record using a Account class instance then if I access the "person" attribute it should check the person_type field and create an instance of NaturalPerson class, or LegalPerson class according to the case!
Something like:
acc = Account(4)
acc.person
"""
if person_type == "L", person returns a LegalPerson instance
but otherwise ...
"""