Sqlalchemy One-to-one, Store Foreign Key In Each Table?
I have a relationship that is one to one between cage codes and duns numbers. I have set up my relationship that looks like, where I store a ForeignKey on each of the respective ta
Solution 1:
I believe you only need to store one foreign key for a one-to-one relationship. See https://docs.sqlalchemy.org/en/13/orm/basic_relationships.html#one-to-one
You shouldn't lose any data access this way. If you remove the duns_id
column from Cage
, you now access the id by cage.duns.id
instead of cage.duns_id
.
Post a Comment for "Sqlalchemy One-to-one, Store Foreign Key In Each Table?"